/*C program to calculate factorial s for 1 to 10 numbers*/
#include <stdio.h>#include<conio.h>
int main(void)
{
int i, j;
int num;
// Outer loop - We want 10 different calculations
for(i = 1;i <= 10;++i)
{
// Initialize num to 1 every time through the outer loop
num = 1;
// Inner loop - Do the actual factorial calculation
for(j = 1;j <= i;++j)
num *= j;
// Print the result - Once each time through the outer loop
printf("%d\t%d\n", i, num);
}
return 0;
}
output
1 12 2
3 6
4 24
5 120
6 720
7 5040
8 40320
9 362880
10 3628800
Comments
Post a Comment