Write a program:
#include
Int main ()
{
int n;
The scanf (" % d ", & amp; N);
for(int i=1; i<=n; I++)
{
Int z=0;
for(int j=1; J<=I/2; J++)
{
If (I % j==0)
Z +=j;
}
If (z==I)
{
Printf (" % d ", z, "its factors are");
for(int j=1; J<=I/2; J++)
{
If (I % j==0)
Printf (" % d ", j);
}
printf("\n");
}
}
return 0;
}
Prompt operation result error, and change the file header and the way of input and output:
#include
#include
using namespace std;
Int main ()
{
int n;
cin> n;
for(int i=2; i<=n; I++)
{
int sum=0;
for(int j=1; J<=I/2; J++)
{
If (I % j==0)
The sum +=j;
}
If (sum==I)
{
Coutfor(int j=1; J<=I/2; J++)
{
If (I % j==0)
Cout
Cout
}
return 0;
}
Run correctly,,
This algorithm is not the same in the two pieces of code? Why the first will go wrong? What distinction do their file header some??
CodePudding user response:
Does anyone know?CodePudding user response:
#includeusing namespace std;
Or
#include
CodePudding user response:
Well, I want to know is that I posted above two code, why a run results will go wrong, right?CodePudding user response:
The first # include & lt; cstdio> Followed byusing namespace std;
Or change to:
#include
CodePudding user response:
The first no namespace declaration namespaceAll the identifiers of the c + + standard library is defined in a namespace called STD
Add a use
CodePudding user response:
Wrong confirm, is compiled, or run,