In this program, we have to find factorial and the number will be taken as input. This program consist of for loop to find n! "for(i=1;i<=n;i++)". variable fact keeps on multiplying by i & i keeps on updating till the no. itself & gives back the result . For eg :- 5! = 5*4*3*2*1;
Program for Factorial.
#include<stdio.h>#include<conio.h>
void main()
{ int n,i,fact=1;
clrscr();
printf("\n program to find factorial");
printf("\n\n enter no. to find factorial : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{ fact = fact*i;
}
printf("factorial = %d",fact);
getch();
}

No comments:
Post a Comment
Guys if you think something is wrong or should be edit than please do comment.