C Program to find the factorial of non-negative numbers


#include <stdio.h>
#include <stdlib.h>

int main()

{
   long num,result=1,i;//initializing data type

    printf("Enter the number: ");

    scanf("%d",&num);//accepting number

    if(num<0)//checking for validity of number

    printf("Invalid number!! \n Enter only possitive numbers");

    else if(num==0)//factorial of zero

    {

    printf("factorial of '0'=  1");}
    
else
    {
    for(i=1;i<=num;i++)
    
    result*=i;//factorial calculation
    
    printf("Factorial of '%d'=   %d",num,result);
    //displaying result
     }

}

Comments