Monday 14 March 2016

Factorial of a number


Write a program to find the factorial of a number using functions.

Function Specification:
int factorial(int n)
The function accepts a int and returns an int.

Input Format: 
Input consists of 1 integer.

Output Format:
Output consists of a single integer. Refer sample output for formatting details.

Sample Input: 
3
Sample Output: 
6

Code:
  #include<stdio.h>
int factorial(int n);
int main()
{
  int n,f;
  scanf("%d",&n);
  f=factorial(n);
  printf("%d",f);
  return 0;
}
int factorial(int n)
{
  int i,sum=1;
  for(i=1;i<=n;i++)
  {
    sum=sum*i;
}
  return sum;
}
  

2 comments:

  1. Candidates can download the Admit Card WBJEE from 10th April 2018. The exam will be conducted on 22nd April 2018 through offline mode (OMR Sheet).

    ReplyDelete
  2. Thank u for this useful information

    ReplyDelete