• Monday, 20 February 2017

    Factorial- Geeksforgeeks


    Question:

    Factorial: Geeksforgeeks

    Calculate the factorial for a given number.


    The first line contains an integer 'T' denoting the total number of test cases. In each test cases, it contains an integer 'N'.

    1<=T<=19
    0<=N<=18

    Input:

        8
        18
        17
        16
        15
        11
        10
        5
        1
    

    Output:

        6402373705728000    
        355687428096000
        20922789888000
        1307674368000
        39916800
        3628800
        120
        1
    



    Code:

    #include<stdio.h>
    long long int factorial(long long int n)
    {
     if (n==0)
     {
      return 1;
     }
     return n*factorial(n-1);
    }
    int func()
    {
     long long int n;
     scanf("%lld",&n);
     printf("%lld\n",factorial(n));
    }
    int main()
    {
     int cases,i;
     scanf("%d",&cases);
     for(i=0;i<cases;i++)
     {
      func();
     }
     return 0 ;
    }
    




    If you like our blog.. Please share ....

    Thanks.... :)

    No comments:

    Post a Comment

    Follow Us on Facebook: