Saturday, April 28, 2018

C program to find the factorial of a number


Program code
#include <stdio.h>
#include <conio.h>
void main()
{
long int question, factorial=1, i;
clrscr();
printf(“Please input an integer to get its factorial.\n”);
scanf(“%ld”,&question);
for (i=question;i>=1;i--)
factorial=factorial*i;
printf(“The factorial of %ld is %ld.\n”,question,factorial);
getch(); 
}

Example of output
Please input an integer to get its factorial.
13
The factorial of 13 is 1932053504.

No comments:

Post a Comment

Please write here, your opinion about this C program