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 );
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: