C program to find the factorial of a given number

by Nideesh C on April 13, 2011 · 0 comments

in C Programming




/*  C program to find the factorial of a given number */

#include <stdio.h>
void main()
{
int  i,fact=1,num;

printf(“Enter the number\n”);
scanf(“%d”,&num);

if( num <= 0)
fact = 1;
else
{
for(i = 1; i <= num; i++)
{
fact = fact * i;
}
}                 /* End of else */

printf(“Factorial of %d =%5d\n”, num,fact);

}                           /* End of main() */

/*——————————————-
Output
Enter the number
5
Factorial of 5 =  120

———————————————*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to check whether a given number is prime or not and output the given number with suitable message
  2. C program to accept a decimal number and conert it binary and count the number of 1′s in the binary number
  3. C program to convert the given binary number into decimal
  4. C program to convert the given binary number into its equivalent decimal
  5. C program to convert the given binary number into its equivalent decimal

Leave a Comment

Previous post:

Next post: