#include
#include
Int fn (int a, int n);//function declaration
Int main (void) {
Int a, n, sum;
int i;
Sum=0;
The scanf (" % d % d ", & amp; A, & amp; n);
//enter a, n
for(i=1; i<=n; I++) {
The sum +=fn (a, I);//loop accumulative
}
Printf (" Sum=% d ", Sum);
return 0;
}
Int fn (int a, int n)
{
Int result=0;
for(int i=0; i
Result=result + a * pow (10, I);//pow says 2 of 3 (2, 3)
}
return result;
}
On the DEV c + + output is the Sum of=98756
In VS 2019 output is the Sum of=98760
I want the result is the Sum of=98760, but the school is DEV compiler,
Two compilers is where step processing lead to different results of different?
Beg big help!!!!!!!!!!
CodePudding user response:
Results should be identified,Is not the same as that of code has a problem, need to modify,,
You also don't say to complete what function, who also can't help you,,,
CodePudding user response:
Topic is this,
CodePudding user response:
Modified as follows, for your reference:# include
#include
Int fn (int a, int n);//function declaration
Int main (int arg c, char * argv [])
{
Int a, n, sum;
int i;
Sum=0;
The scanf (" % d % d ", & amp; A, & amp; n);//enter a, n
for(i=1; i<=n; I++) {
The sum +=fn (a, I);//loop accumulative
}
Printf (" Sum=% d ", Sum);
system("pause");
return 0;
}
Int fn (int a, int n)
{
Int result=0;
for(int i=0; iThe result +=a * pow (10, I);//pow says 2 of 3 (2, 3)
}
return result;
}
CodePudding user response:
This is the building in front of the code, it is correct, this is to modify, another kind of writing, for reference:# include
Int fn (int a, int n);//function declaration
Int main (int arg c, char * argv [])
{
Int a, n, sum;
int i;
Sum=0;
The scanf (" % d % d ", & amp; A, & amp; n);//enter a, n
for(i=1; i<=n; I++) {
The sum +=fn (a, I);//loop accumulative
}
Printf (" Sum=% d \ n ", Sum);
system("pause");
return 0;
}
Int fn (int a, int n)
{
Int result=0;
for(int i=0; i//result + (10, I)=a * pow.//pow says 2 of 3 (2, 3)
Result=result * 10 + a;
}
return result;
}
CodePudding user response:
Show a, only supplies the reference:# include & lt; stdio.h>
Int fn (int a, int n)
{
If (n==1) return a;
The else return a * (10 * fn (1, n - 1) + n);
}
Int main (void)
{
Int a, n.
The scanf (" % d % d ", & amp; A, & amp; n);
Printf (" Sum=% d ", fn (a, n));
return 0;
}
CodePudding user response:
The