Write a program to find the factorial of a number
#include<stdio.h>
#include<conio.h>
int main()
{
int i=1,fact=1,num;
printf("Enter a number: ");
scanf("%d",&num);
while(i<=num)
{
fact=fact*i;
i++;
}
printf("Factorial of %d is: %d",num,fact);
return 0;
}
Sample output:
Enter a number: 5
Factorial of 5 is: 120
#include<stdio.h>
#include<conio.h>
int main()
{
int i=1,fact=1,num;
printf("Enter a number: ");
scanf("%d",&num);
while(i<=num)
{
fact=fact*i;
i++;
}
printf("Factorial of %d is: %d",num,fact);
return 0;
}
Sample output:
Enter a number: 5
Factorial of 5 is: 120
No comments:
Post a Comment