I'm about as new as they come to programming. Taking a class on it for the first time this semester. I'm writing a program that takes an integer (n) as the input and outputs every integer from 1 to n, their factorials, and the factorials of (n-1).
It should look something like this:
n |
n! |
(n-1)! |
1 |
1 |
1 |
2 |
2 |
1 |
3 |
6 |
2 |
4 |
24 |
6 |
The problem is that instead of outputting the subsequent integers, I'm getting the final line repeated n times.
Also aware this might not be the most efficient way to do this. That's a secondary concern right now.
Code:
#include <stdio.h>
int main(void)
{
int i, j; //Variables for output lines 1 to n-1
int n, start, factor, fin; //n! variables
int startm, factorm, finm; //(n-1)! variables
printf("Please enter the number of factorials you wish to output: ");
scanf_s("%i", &n);
printf(" n n! (n-1)!\n-------------------\n");
//start of output lines 1 to n-1 loop
for (i = 1; i <= n; i++) {
//start of n! loop
for (start = 1; start <= n; start++) {
fin = 1;
for (factor = 1; factor <= n; factor++) {
fin = fin*factor;
}
}
//start of (n-1)! loop
for (startm = 1; startm <= n; startm++) {
finm = 1;
for (factorm = 1; factorm < n; factorm++) {
finm = finm*factorm;
}
}
printf("%i %i %i\n", n, fin, finm);
}
getch();
return(0);
}