Home / Programs / C Program - Write a program to find the factorial of a number using for loop
Programming Example

C Program - Write a program to find the factorial of a number using for loop

👁 1,133 Views
💻 Practical Program
📘 Step by Step Learning
Write a program to find the factorial of a number

Program Code

#include"stdio.h"
int main()
{
	int n, c;
	long int f=1;
	printf("\n Enter the number:");
	scanf("%d",&n);
	if(n<0)
		goto end;
	for(c=1; c<=n; c++)
		f*=c;
	printf("\n FACTORIAL IS %ld", f);
	end:
        
     getch();   
	return 0;
}

Output

 Enter the number:5

 FACTORIAL IS 120

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.