#include<stdio.h>
int main()
{
int factorial, i, number;
printf("Find Factorial of a Number using for loop in C \n");
printf("Enter number:");
scanf("%d", &number);
if (number<0)
{
printf("factorial of %d is undefined \n", number);
printf("Press enter to continue... \n");
fflush(stdin);
getchar();
return 0;
}
factorial = 1;
for (i = number; i>1; i--)
{
factorial *= i;
if (factorial <= 0)
{
printf("Arithmetic Overflow occurs. The Factorial may be too large to be represented in factorial variable \n");
printf("Press enter to continue... \n");
getchar();
return 0;
}
}
printf("Factorial of %d is %d \n", number, factorial);
printf("Press enter to continue... \n");
fflush(stdin);
getchar();
return 0;
}
|
Find Factorial Program in C Language
C Program