11:58 PM 2010-2011 question 2 |
write program print out the factorial of n integer values , the program passes each integers value to a function called factorial that calculates the fact of an integer value
#include"stdio.h"
int factorial(int f);
main()
{
int n, val, i;
printf("enter num of values : ");
scanf("%d", &n);
for(i=1;i<=n;i++){
printf("enter value no. %d : ", i);
scanf("%d", &val);
printf("fact = %d\n", factorial(val));
}
getch();
return 0;
}
int factorial(int x)
{
int i, fact=1;
for(i=1;i<=x;i++)
fact*=i;
return fact;
}
|
|
Total comments: 0 | |