Wednesday, 22 June 2016

Program in C to find factorial of a No.

Following is the program to find factorial of a No. :-





#include<stdio.h>

int main()

{

int a,fact,n;
fact = 1;

printf("***Program to find factorial of a number***\n\n");

printf("Please enter a number\n");

scanf ("%d", &a);

for(n=a; n>0; n--)

{
fact = fact * n;
}

printf("The factorial is %d",fact);

return 0;

}
Output-











Note- using the same logic we can design this program in C++ too

No comments:

Post a Comment