English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

the program should use the while loop

2007-02-16 21:04:18 · 6 answers · asked by bluemiano 2 in Computers & Internet Programming & Design

sorry guys using the c programing language.

2007-02-16 21:24:28 · update #1

dragongml, why not a semicolon after the i--?

2007-02-16 21:42:58 · update #2

6 answers

//java statement
int x=1;
int sum=0;
while (x<=100)
{
sum+=x;
x++;
}
System.out.println("sum of whole numbers between 1 and 100 is= "+sum);

2007-02-16 21:10:12 · answer #1 · answered by abd 5 · 0 1

Well let's say you were adding the numbers from one to five one at a time.

You would do:
1+2 = 3
3 + 3 = 6
6 + 4 = 10
10 + 5 = 15

Do you see a pattern developing here?

You are taking the sum of the numbers from 1 to 2 and adding it to the next number in the sequence: 3.
Then you are taking the sum of the numbers from 1 to 3 and adding it to the next number in the sequence: 4
Then you are taking the sum of the numbers from 1 to 4 and adding it to the next number in the sequence: 5...

And you are DOing this WHILE the next number in the sequence is not greater than 100...

Do you get it?

2007-02-17 05:12:09 · answer #2 · answered by Anonymous · 1 0

You would need something like (pseudo code):

variables: Total, Counter as Integer

Total = 0
Count = 100

While Count >0
Total = Total + Count
Count = Count -1
End While

Display Total

2007-02-17 05:12:54 · answer #3 · answered by Lewiy 3 · 0 0

do something like this in c++

int x

cin>>x

int y

y=(x(x+1))/2

cout>>y

where x is the largest number in the list.

2007-02-17 05:10:24 · answer #4 · answered by Anonymous · 0 0

int i =100;

int x=0;

while (i>0) {
x++;
i--

}

2007-02-17 05:32:04 · answer #5 · answered by dragongml 3 · 0 0

vb the for next statement

2007-02-17 05:38:50 · answer #6 · answered by Nerd 4 · 0 0

fedest.com, questions and answers