Void main ()
{
int sum=0;
int i;
For (I=1; I & lt;=100; I++)
{if (I % 2==0)
{
Sum=sum + I;
}
Printf (" % d \ n ", sum);
}
}
CodePudding user response:
for (I=1; I & lt;=100; I++)
{if (I % 2==0)
{
Sum=sum + I;
}
Printf (" % d \ n ", sum);
}
Have a look at the code, your printf is inside the for loop, that is to say, every even number add you output the sum again
If just want to be the final result, placed the printf in a layer of outside is ok!
# include & lt; stdio.h>
Void main ()
{
int sum=0;
int i;
For (I=1; I & lt;=100; I++)
{if (I % 2==0)
{
Sum=sum + I;
}
}
Printf (" % d \ n ", sum);
}
CodePudding user response:
You put thePrintf (" % d \ n ", sum);
Take out
On the outside of the for loop try