answersLogoWhite

0


Best Answer

int i, sum;

/* example using while */

sum = 0;

i = 1;

while (i <= 100) {

sum += i;

++i;

}

/* example using for */

sum = 0;

for (i = 1; i <= 100; ++i) sum += i;

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write while andfor loop to get sum of1to100 integer?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write 31 as an integer?

31 is an integer.


How do you write 001 as a fraction?

001 is the same as the integer 1 and so you would write it as 1.001 is the same as the integer 1 and so you would write it as 1.001 is the same as the integer 1 and so you would write it as 1.001 is the same as the integer 1 and so you would write it as 1.


What is 147000 as a fraction?

It is an integer, not a fraction, but if you must, you could write it as 147000/1.It is an integer, not a fraction, but if you must, you could write it as 147000/1.It is an integer, not a fraction, but if you must, you could write it as 147000/1.It is an integer, not a fraction, but if you must, you could write it as 147000/1.


How do you write 14494 as an integer?

-14,494


How do you write 5789 as an integer?

The number 5789 is already an integer.


How do you write 1440 as an integer?

1440 is an integer.


Write a program using while loop with breaking?

So to answer this you should recognize that various loops can be rewritten as such. For example - and to give the short answer to your question:int iLoop = 0;while(1){if(iLoop > 5)break;elseiLoop++;}This is the same as:int iLoop = 0;do{if(iLoop++ > 5)break;} while(1);andfor(int iLoop = 0; iLoop < 5; iLoop++){//...}


How do you write 2 million as an integer?

2,000,000 an integer is any whole number


Write a program to subtract integer y from integer x?

x -=y;


How do you write 187 as an integer?

187 is already an integer because it is a whole number


How do you write 500 percent as an integer?

500% as an integer or whole number is 5


How do you write an integer expression?

-(17)