Program to calculate Factorial of a given number

#include
#include

void main()
{
    int num, fact = 1;
    clrscr();
    /*Accept a number from the user*/
    printf("\nEnter the number: ");
    scanf("%d", &num);
    
    /*Calculate the factorial*/
    for(int i=1; i<=num; i++)
    {
    	fact = fact * i;
    }
    
    /*Display the result*/
    printf("The factorial of %d is %d", num, fact);
    getch();
}

Output:

Enter the number: 5
The factorial of 5 is 120

You may also like...

4 Responses

  1. Jyant Khosla says:

    void main(){
    int n,s=1;
    printf(“enter the nth value”);
    scanf(“%d”,&n);
    while(n>0)
    {
    s=s*n;
    n–;
    }
    printf(“the answer is %d”,s);
    getch();
    }

  2. shubha says:

    i get ans fr factorial oly up to 10

  1. March 1, 2014

    […] Progarm to calculate Factorial of a given number […]

  2. October 25, 2017

    […] Progarm to calculate Factorial of a given number […]

Leave a Reply

Your email address will not be published. Required fields are marked *