For Loop Example 9 : Write a program to compute the factorial of a given number.
Solution:
#include <stdio.h>
#include <conio.h>
void main()
{
int i=1,n;
unsigned long fact=1;
clrscr();
printf("\nENTER A NUMBER: ");
scanf("%d",&n);
for(i=1;i<=n;i+=1)
{
fact=fact*i;
}
printf("\nFACTORIAL OF %d IS %lu",n,fact);
getch();
}
No comments:
Post a Comment