C Code 1 _ To find Factorial of the given number

C Code 1 _ To find Factorial of the given number


Program :


#include<stdio.h>
int main()
{
    long int f=1;
    int n,i;
    printf("Enter a number : ");
    scanf("%d",&n);
    if(n<0)
    {
           printf("Enter a value greater than zero");
    }
    else if(n==0)
    {
         printf("The factorial of 0 is 1");
    }
    else
    {
        for(i=n;i>=1;i--)
        {
            f=f*i;
        }
        printf("The factorial of %d is %ld ",n,f);
    }
    getch();
    return 0;
}



Output :










Thank you ...

Popular Posts