A
action!
this is my C Programming homework,
It wants me to input 10! and output the follow result
10!
¡õ
10 * 9!
¡õ
9 * 8!
..................
2* 1!
¡õ
1
I take it for decreasing by degress, so using two for() loop to execute..
but I spend two days to try and can not figure out what the problem is.
Could anybody show me a hint with this ? thank you so much.
I use the compiler with dec C++ to finish the C programming follow
----------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
long fact(int num);
int main(void)
{
int i,j; /* counter */
int ans = 1;
printf("Input the n!:");
scanf("%d", &i);
for(i=10;i>=1;i--)
{
for(j=9;j>=0;j--)
{
ans *= j;
printf("%d * %2d! = %d\n",i, j, i*j );
}
printf("\n");
}
system("pause");
return 0;
}
/* Recursive fonction */
long fact(int num)
{
if(num<=1){
return 1;
}
else{
return (num * fact(num-1));
}
}
It wants me to input 10! and output the follow result
10!
¡õ
10 * 9!
¡õ
9 * 8!
..................
2* 1!
¡õ
1
I take it for decreasing by degress, so using two for() loop to execute..
but I spend two days to try and can not figure out what the problem is.
Could anybody show me a hint with this ? thank you so much.
I use the compiler with dec C++ to finish the C programming follow
----------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
long fact(int num);
int main(void)
{
int i,j; /* counter */
int ans = 1;
printf("Input the n!:");
scanf("%d", &i);
for(i=10;i>=1;i--)
{
for(j=9;j>=0;j--)
{
ans *= j;
printf("%d * %2d! = %d\n",i, j, i*j );
}
printf("\n");
}
system("pause");
return 0;
}
/* Recursive fonction */
long fact(int num)
{
if(num<=1){
return 1;
}
else{
return (num * fact(num-1));
}
}