02.12.2014
Factorial C program,Algorithm,Flowchart
Q. Write a C program to find the factorial value of a number. Also write the algorithm and draw flowchart.
Ans.
/*c program to find out factorial value of a number*/ #include<stdio.h> #include<conio.h> int main() {
int n,i,fact=1;
printf("Enter any number : ");
scanf("%d", &n);
for(i=1; i<=n; i++)
fact = fact * i;
printf("Factorial value of %d = %d",n,fact);
return 0; }
Ans.
/*c program to find out factorial value of a number*/ #include<stdio.h> #include<conio.h> int main() {
int n,i,fact=1;
printf("Enter any number : ");
scanf("%d", &n);
for(i=1; i<=n; i++)
fact = fact * i;
printf("Factorial value of %d = %d",n,fact);
return 0; }
And Here is the Algorithm And Flowchart
Algorithm for calculate factorial value of a number:
[algorithm to calculate the factorial of a number] step 1. Start step 2. Read the number n step 3. [Initialize]
i=1, fact=1 step 4. Repeat step 4 through 6 until i=n step 5. fact=fact*i step 6. i=i+1 step 7. Print fact step 8. Stop [process finish of calculate the factorial value of a number]
Flowchart for calculate factorial value of a number:
[algorithm to calculate the factorial of a number] step 1. Start step 2. Read the number n step 3. [Initialize]
i=1, fact=1 step 4. Repeat step 4 through 6 until i=n step 5. fact=fact*i step 6. i=i+1 step 7. Print fact step 8. Stop [process finish of calculate the factorial value of a number]
Flowchart for calculate factorial value of a number:
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.