Program Statement: In the Mini project second function is to find factorial of a number. Mukesh allotted this function to Shankar.
Help Shankar to write a program to find the factorial of a number using functions.
Function Specification:
int factorial(int n);
Input Format:
Input consists of 1 integer.
Output Format:
Output consists of a single integer.
Refer sample input and output for formatting details.
Sample Input:
3
Sample Output:
6
Implementation of above problem:
#include<stdio.h>
int factorial(int);
int main()
{
int number;
//int fact = 1;
scanf("%d",&number);
printf("%d",factorial(number));
return 0;
}
int factorial(int n)
{
int c;
int result = 1;
for( c = 1 ; c <= n ; c++ )
result = result*c;
return ( result );
}
Thanks
Mukesh Rajput
Post A Comment:
0 comments: