[My site ]
Main » 2013 » December » 12 » 2010-2011 question 2
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;
}
Category: C Programming - 1 | Views: 345 | Added by: ahansaary | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Sign Up | Login ]