-
factorial output
how can i get my output of a factorial to look like this:
Enter a number: 5
Factorial expansion phase:
5
4
3
2
1
Factorial wrapup phase:
1
2
6
24
120
The factorial of 5 is 120.
im using the function below to find factorial:
int factorial(int n)
{
if (n == 0)
return 1;
else
return (n * factorial (n - 1));
}
-
getting there!!!
#include <stdio.h>
int factorial(int same){....}
int main(void)
{
int origi,other,fact;
printf("Enter a Number: ");
scanf("%d",&other);
origi = other;
printf("Factorial Expansion phase: \n");
do{
other--;
printf("%d\n",other);
}while(other >= 1);
printf("Factorial Wrapup phase: \n");
do{
other++;
fact = factorial(other);
printf("%d\n", fact);
}while(other >= origi);
printf("The factorial of %d is %d\n",other,fact);
return 0;
}