Monday, August 4, 2014

Factorial of a number

Program to calculate the factorial of a number:

Solution:


 /*
 * Factorial of a number
 * Written by Shaeed Khan. 
 * Date: 04 Aug 2014
 * Version- 1.0 
 */

#include < stdio.h >  
#include < stdlib.h > 

void main()
{
 int x,n;
 printf("Enter a number :");
 scanf("%d",&n);
 x=fact(n);
 printf("%d",x);
}

int fact(int n)
{
 int f=1;
 while(n>0)
 {
  f=f*n;
  n--;
 }
 return f;
}

No comments:

Post a Comment