Tuesday, 9 December 2014

C Program to find Factorial of a number

Program to find Factorial of a number
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void factorial(int n)
{
int fact=1,i;
for(i=1;i<=n;i++)
fact=fact*i;
printf("factorial of %d =%d\n",n,fact);
}
main(int argc,char **argv)
{
int i,num;
for(i=1;i<argc;i++)
{
num=atoi(argv[i]);
factorial(num);
}
}
OutPut:
madan@madan-Lenovo-G570:~/madan$ ./a.out 5
factorial of 5 =120