Calculate The Factorial Of A Given Number



Source code :-

#include<stdio.h>
int main()
{
    long int i,n,f=1;
    printf("Enter the number: ");
    scanf("%ld",&n);
    for(i=1;i<=n;i++)
        f=f*i;
    printf("\nThe factorial of %ld is %ld\n",n,f);
    return 1;   
}

Input-Output :-

abhi@hp-15q-laptop:~$ gcc factotial.c
abhi@hp-15q-laptop:~$ ./a.out
Enter the number: 5
The factorial of 5 is 120

Post a Comment

Previous Post Next Post