In the Mini project, the second function is to find the factorial of a number. Rita allotted this function to Johnny.
Help Johnny 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:
The output consists of a single integer.
Refer sample input and output for formatting details.
Sample Input:
3
Sample Output:
6
Program Code:
#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 );
}
Post A Comment:
0 comments: