Home > Back-end >  To solve the reason for the error
To solve the reason for the error

Time:06-11

[title description]
Given a positive integer n, o not greater than the positive integers n factorial and (namely for 1! + 2! + 3! +... + n!) , and output factorial,
[enter]
Input a line containing a positive integer n (1 & lt; N & lt; 12),
[output]
Output one line: factorial and,
[input sample]
5
[output sample]
153





#include
Int main ()
{
Int t, I, n, m=1, s=0;
The scanf (" % d ", & amp; n);
For (t=1; T<=n; T++)
{
for(i=1; i<=t; I++)
{
I m=m *;
}
S=s + m;
}
Printf (" % d ", s);
return 0;
}



Why the output of the answer right? Don't know where the code wrong great god solve

CodePudding user response:

Int type may not enough storage, overflow, isn't it? Try changing long long

CodePudding user response:

Do you want to include maths!
If missed this

CodePudding user response:

 
For (t=1; T & lt;=n; T++)
{
M=m * t;
S=s + m;
}

CodePudding user response:

 # include & lt; stdio.h> 
Int main (void) {
Int n, sum=0, m=1;
Scanf_s (" % d ", & amp; n);
for (int i=1; I & lt;=n; + + I) {
M *=I;
The sum +=m;
}
Printf (" % d \ n ", sum);
return 0;
}
/*
12
522956313
Please press any key to continue...
*/

CodePudding user response:

 # include & lt; stdio.h> 

Int main ()
{
Int t, I, n, m=1, s=0;

The scanf (" % d ", & amp; n);
For (t=1; T<=n; T++)
{
for(i=1; i<=t; I++)
{
I m=m *;
}
S=s + m;
M=1;//to assign a value of 1
}
printf("%d\n",s);

return 0;
}


For your reference ~

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related