Home > Back-end >  Strives for the bosses
Strives for the bosses

Time:09-20

C language to write 1 * 2 * 3... * 20

CodePudding user response:

 
#include

Int main ()
{
Int I, s=1;
For (I=1; i <21. I++)
S *=I;
Printf (" % d ", s);
return 0;
}

CodePudding user response:

Recursive
#include
#include

Int fac (int n)
{
If (n & lt;
=1){
return 1;
}
The else
{
Fac return n * (n - 1);
}

}
Int main ()
{
int n=0;
Printf (" please enter a number: ");
Scanf_s (" % d ", & amp; N);//the input you find such as the product of the above 20
Int fac (n);
Printf (" % d \ n ", fac (n));
system("pause");
return 0;
}

CodePudding user response:

LS two methods can, but the result is beyond the scope int, so it's best to change the int type double

CodePudding user response:

The
reference 1 floor? Victor.?? Response:
 
#include

Int main ()
{
Int I, s=1;
For (I=1; i <21. I++)
S *=I;
Printf (" % d ", s);
return 0;
}

S spilled into consideration?

CodePudding user response:

S consider the unsigned long long or the double

references 4 building self-confidence boy reply:
Quote: refer to 1st floor? Victor.?? Response:

 
#include

Int main ()
{
Int I, s=1;
For (I=1; i <21. I++)
S *=I;
Printf (" % d ", s);
return 0;
}

S spilled into consideration?

CodePudding user response:

references 4 building self-confidence boy reply:
Quote: refer to 1st floor? Victor.?? Response:

 
#include

Int main ()
{
Int I, s=1;
For (I=1; i <21. I++)
S *=I;
Printf (" % d ", s);
return 0;
}

S spilled into consideration?


Does
Thank you for remind
Ill-considered ~
  • Related