Home > Back-end >  The C language
The C language

Time:09-28

I the purpose of this program is to add 1 to 100, and is something wrong? Have a great spirit to give directions? A freshman C language for beginners!

CodePudding user response:

I want to know you I was used to record what of,

If I were starting position, so I=1, the output is 5050, and the answer is right,

 
# include & lt; Stdio. H>

Void main () {
Int I, sum=0;
Printf (" please enter an I value ");
The scanf (" % d ", & amp; i);
While (i<{
=100)Sum=I + sum;
i++;
}
Printf (" sum=% d ", sum);
}



If I was terminated position, so I=100, when the answer 5050.
 
# include & lt; Stdio. H>

Void main () {
Int I, sum=0;
Printf (" please enter an I value ");
The scanf (" % d ", & amp; i);
While (I) {
The sum +=I;
I -;
}
Printf (" sum=% d ", sum);
}

CodePudding user response:

reference 1st floor Ljnoit response:
I want to know what I was used to record you,

If I were starting position, so I=1, the output is 5050, and the answer is right,

 
# include & lt; Stdio. H>

Void main () {
Int I, sum=0;
Printf (" please enter an I value ");
The scanf (" % d ", & amp; i);
While (i<{
=100)Sum=I + sum;
i++;
}
Printf (" sum=% d ", sum);
}



If I was terminated position, so I=100, when the answer 5050.
 
# include & lt; Stdio. H>

Void main () {
Int I, sum=0;
Printf (" please enter an I value ");
The scanf (" % d ", & amp; i);
While (I) {
The sum +=I;
I -;
}
Printf (" sum=% d ", sum);
}

Can you tell anything wrong, and the correct letter to me have a look at it

CodePudding user response:

Look at the,
A=1, b=100
Sum=5050

 
# include & lt; Stdio. H>

Void main () {
Int a, b, sum=0, I;
The scanf (" % d % d ", & amp; A, & amp; B);
For (I=a; I<=b; I++) sum +=I;
Printf (" sum=% d ", sum);
}


Your code:
I said if it is a starting position, that is right,
I said if it is terminated position, and that is wrong,

Right on the 1st floor back,

CodePudding user response:

And your third line should be:
Int I, sum=0;

To add a comma with a semicolon,
  • Related