# Thread: HELP me Factorial Recursive

1. ## HELP me Factorial Recursive

can you guys tell me why this wont do the factorial math!!

#include <stdio.h>
#include <conio.h>
#include <ctype.h>

main()
{
int n, total, i;
total = 1;
printf("Enter a natural number: ");
scanf ("%d", &n);

while (n < 0)
{
printf ("Error Please Re-Enter Your Natural Number");
scanf ("%d", &n);
}
i = 1;

for (n > 0; i = n; i++)
{
total = total * i;
}
printf ("%d", total);

fflush(stdin);
getch();
return 0;
}

2. This should probably be in 'C Programming' not 'C++ Programming'.

3. Use code tags, please

Code:
`for (n > 0; i = n; i++)`
This for loop is wrong. What you probably want is for (int i = 1; i <= n; i++)

4. ... and beyond the above posts, it should also be mentioned that your method isn't recursive as the topic would imply. Now, when you wrap the code in code tags... I'll tell you about the several things that aren't standard in your code.

5. Please stop cross-posting.

6. >> Please stop cross-posting.
The suggestion was made to put it in the C forum. My guess is that the OP just followed the suggestion.

Popular pages Recent additions