UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to find factorial of a number

C program for how to factorial of a given number

by Krishna viswambharan


Posted on 16 Aug 2017 Category: C Views: 1355

Edited on 25 Aug 2017


C program to find factorial of a number

The factorial of a given number is calculated as 1*2*3*….n . Here is another sample program for ‘for loop’. 

This program takes a positive integer from the user and compute the factorial using the ‘for loop’.

Program to find factorial of a number in c using for loop

#include <stdio.h>
#include <conio.h>
void main()
{
	int n,i,factorial=1; //if we want to find the factorial of a large number we can declare the factorial variable datatype as 'unsigned long long'
	printf(“Enter the number :”);
	scanf(“%d”,&n);
	for(i=0;i<=n;i++)
	{
		factorial=factorial*i;   //compute factorial
	}
	printf(“The factorial of the number is %d”,factorial);
	getch();
}

OUTPUT

Related article

C program to find factorial of a number using While loop

C program to study while loop

C program to study 'do-while' loop



Leave a Comment:


Advertisement