C program to find the factorial of a number

Estimated read time 2 min read



include

C program to find the factorial of a number first declares three integer variables – num, fact and i.

It prompts the user to enter a number using the printf and scanf functions.

Using a for loop, the program calculates the factorial of the entered number.

Finally, the program uses the printf function to output the factorial of the entered number to the user.

int main() {
int num, fact=1, i;
printf("Enter a number: ");
scanf("%d", &num);

for(i=1; i<=num; i++) {
    fact = fact * i;
}

printf("Factorial of %d is %d", num, fact);

return 0;
}

Output:

Enter a number: 5
Factorial of 5 is 120

C program to find the factorial of a number
C program to find the factorial of a number
output
output
admin https://study-from-here.com

Digital Marketing Consultants and Social Media Marketing Expert with over 3 years of rich experience in various Branding, Promotions, business directories, On pages and off page optimization, Link building Advertising, Research, paid advertisement, content writing and marketing

You May Also Like

More From Author

+ There are no comments

Add yours