Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

C Program to Print Factorial of any given number

YASH PAL, 31 July 20241 September 2024

In this tutorial, we are going to make a C Program to print a Factorial of any given number entered by the user.

C Program to Print Factorial of any given number

What is a Factorial of a Number?

The factorial of a number is equal to the multiplication of the number’s factors. let’s say we want to get the factorial of number 4. so the factorial of number 5 is 1*2*3*4*5 =  120. now let’s make a c program to print the factorial of a given number.
#include<stdio.h>
#include<conio.h>

void main()
{

           int input, i, fact=1;

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

           for( i=1; i<=input; i++)
               fact= fact*i;

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

         getch();
}

Output

C Program to Print Factorial of any given number

Explanation

Here first we include the two header files stdio.h and conio.h. after that we declare the main function. and inside that, we declare the three variables input, i, and fact, and set the value of fact variable to 1. after that we print the message on the screen “Enter any number:” using printf() function. and then we scan the value that given or enter by the user in the input variable using the scanf() function.
after that, we use the for loop to find the factorial of the given number. remember the for loop will increase the value of i and multiply with the fact variable. and the loop will run till the value of i will not equal the input variable.
now using the printf() function we print the factorial and the message on the output screen.
c coding problems cPrograms

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes