Friday, August 17, 2018

FACTORIAL

       Problem Description

Write a program to find the factorial value of any number entered by the user.

CODING ARENA::

#include <stdio.h>
int fact(int x);
int main()
{
  int n,i;
  scanf("%d",&n);
  int a,f;
  for(i=0;i<n;i++)
  {
   
    scanf("%d",&a);
    f=fact(a);
    printf("\n%d",f);
  }
  return 0;
}
int fact(int x)
{
  int i,r=1;
  for(i=1;i<=x;i++)
  {
    r=r*i;
  }
  return r;
}
   
   
   
   Test Case 1

Input (stdin)
3



3 4 5



Expected Output
6



24



120
Test Case 2

Input (stdin)
3



7 8 6



Expected Output
5040



40320



720


No comments:

Post a Comment