C Programming

C Program to Find the Factorial of Entered Number

Write a c program to take input from user and find the factorial

C Code

#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{

int i, number, factorial =1;

printf("Enter number : ");
scanf("%d",&number);

if(number<0)
printf("error:negative number");

else if(number==0)
printf("factorial of 0 i 1");

else{
for (i=1; i<=number; i++)
factorial*=i;
printf("factorial is of %d is %d",number, factorial);
}

getch();
}

Output

Related Articles

Back to top button

Adblock Detected

Please turn off your Adblocker to view your content.