Write a program to find the factorial of a given number using while loop.
Program :
#include<stdio.h>
void main()
{
int n;
long int fact;
scanf("%d",&n);
int i=1;
fact = 1;
while(i<=n)
{
fact*=i;
i++;
}
printf("The Factorial of %d is : %ld",n,fact);
}
Input | Output | |
Test Case 1 | 5 | The Factorial of 5 is : 120 |
Test Case 2 | 10 | The Factorial of 10 is : 3628800 |
No comments:
Post a Comment