Navigate back to the homepage

A Program to display factorial of specified number using for loop in C

Vishnu Damwala
March 1st, 2020 · 1 min read

A tutorial to finding factorial for integer data-type using for loop in C - language

Working example:

1/**
2 * Factorial For N Using For Loop
3 */
4#include <stdio.h>
5int main()
6{
7 int i, n, result = 1;
8 printf(" Enter number: ");
9 scanf("%d", &number);
10
11 for (i = 1; i <= number; i += 1)
12 {
13 // printf("\n I : %d", i);
14 // printf("\n Result B4 : %d", result);
15 result *= i;
16 // printf("\n Result After : %d", result);
17 }
18 printf("\n Factorial of %d : %d", number, result);
19 printf("\n");
20 return 0;
21}

Output for number 5:

1Enter number: 5
2
3Factorial of 5 : 120

Output for number 6:

1Enter number: 6
2
3Factorial of 5 : 720

More articles from MeshWorld

How to find the length of a string using strlen() in C

C program to find length of a string, for e.g, length of "East or West INDIA is best" is 26 (including space and excluding null character).

February 25th, 2020 · 1 min read

Convert hexadecimal color to rgb or rgba in php

Convert hexadecimal color to rgb or rgba in php

February 7th, 2020 · 1 min read
© 2017–2020 MeshWorld
Link to $https://twitter.com/meshworldindiaLink to $https://facebook.com/meshworldindiaLink to $https://instagram.com/meshworld.india/