CodesJava

Easy learning with example program codes

C program to print factorial of a number


The below program prints factorial of a number using a loop. The C printf statement is used to output the result on the screen. The factorial of a number can be calculated for positive integers only and is represented by n!.

n! = n*(n-1)*(n-2)*……*1
0! = 1

C program to print factorial of a number

#include <stdio.h>
 
void main()
{
 
int num,i;
int f = 1;    
 
printf("Enter a number:");    
scanf("%d",&num);  
 
for (i=num; i>=1; i--)   
{  
f = f * i;  
}  
 
printf ("%d! = %d",num,f);  
}

Output

Enter a number:5
5! = 120
Posted in C   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki