Factorial program in c: In this program, we are going to find the factorial of any number using for loop. 

Enter a number: 8

Factorial of 8 is 40320  

Table Of Contents

Factorial Program in c using for loop

#include <stdio.h>

int main()
    int num, i,n;
    printf("Enter a Number:");
    scanf("%d", &num);
    for (i = num - 1; i >= 1; i--)
        num = num * i;
    printf("Factorial of %d is %d",n,num);

Factorial program in c using for loop

Algorithm to make Factorial program:

  • Initialize an int variable and take its input from the user using scanf.
  • Use for loop, initialize i with the value one less than the number given by the user.
  • The testing condition is that our loop variable should be greater than 1.
  • The updating expression will be i– which decreases the value of i by one.
  • Now multiply the num variable by our loop variable.
  • Now, you can print our variable num which shows the factorial of the number entered by the user. 

Factorial is represented by “!”.
4! = 4*3*2*1 = 24
n! = n*(n-1)*n-2)*…..*1

How to Make a Factorial Program in C using for-loop

In this post, I have provided source code and an approach to make a factorial program in c using for loop.

I have a 5-minute task for you today. If you do it, it will take you one step closer to becoming a programmer.

I know you have already installed turbo c++ or another compiler on your device, but I bet you cannot make a C program to determine the factorial of a number correctly. If you can do so then very well, You can check other programs as well on this site.

So, If you are not able to do so then don’t worry about it.  You have to just follow the algorithm and source code. That way you can get a better understanding of what you need to make a factorial program in c using for loop.

Also, this week, I’ve covered a few more lessons when it comes to your Coding training:
Prime number program in c– I break down the source code in many ways like using for-loop, while-loop, do-while loop, and using functions also.
Palindrome program in c– In this lesson, I have given you the source code which helps you to make a program to check whether the number is palindrome or not.
If you have any queries let me know by commenting below.

Hope your programming training is going well.