Home > Back-end >  Use DEV C and VS 2019 compile the same code output is not the same!!
Use DEV C and VS 2019 compile the same code output is not the same!!

Time:12-11

As title, code:
#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
reference 3 floor QZJHJXJ response:
modify as follows, for 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;
}

What is the meaning of the fourth row?

CodePudding user response:

reference 1st floor ctrigger response:
results should be determine,
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,,,

Topic has hair, help see

CodePudding user response:

refer to 7th floor AruNi °? Response:
Quote: refer to 1st floor ctrigger response:
results should be determine,
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,,,

Look on the subject has hair, help


The fifth floor, I wrote, for reference only,

CodePudding user response:

Bosses, how do you want to come out the recursive function?

CodePudding user response:

refer to the eighth floor ctrigger response:
Quote: refer to 7th floor AruNi °? Response:
Quote: refer to 1st floor ctrigger response:
results should be determine,
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,,,

Look on the subject has hair, help


The fifth floor, I wrote, for reference only.

Bosses, how do you think of the recursive function? O idea!  nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related