1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
algol [13]
3 years ago
12

Write a while loop that adds the first 100 numbers (from 1 to 100) together. To do so, use a while loop that continues while the

condition of cur_num being less than or equal to stop_num is True. Inside the loop, it should add cur_num to the running total variable, and also add 1 to cur_num. Make sure to check at the end that the value of total reflects the total summation.

Computers and Technology
2 answers:
Anettt [7]3 years ago
6 0

Answer:

cur_num = 0

stop_num = 100

total = 0

while cur_num <= stop_num:

   total += cur_num

   cur_num += 1

print(total)

Explanation:

Initialize the variables

Initialize a while loop that iterates while cur_num is smaller than or equal to stop_num

Add the cur_num to total in each iteration to calculate the total

Increase the cur_num at then end of each iteration to control the loop

When the loop is done, print the total

Andreas93 [3]3 years ago
6 0

Answer:

I am writing JAVA and C++ program. Let me know if you want the program in some other programming language.  

Explanation:

JAVA program:

public class SumOfNums{

public static void main(String[] args) { //start of main function

int cur_num   = 1; // stores numbers

int stop_num= 100; // stops at this number which is 100

int total = 0; //stores the sum of 100 numbers

/* loop takes numbers one by one from cur_num variable and continues to add them until the stop_num that is 100 is reached*/

while (cur_num <= stop_num) {

 total += cur_num; //keeps adding the numbers from 1 to 100

//increments value of cur_num by 1 at each iteration

 cur_num = cur_num + 1;}

//displays the sum of first 100 numbers

System.out.println("The sum of first 100 numbers is: " + total); }}  

Output:

The sum of first 100 numbers is: 5050

C++ program

#include <iostream> //for input output functions

using namespace std; //to identify objects like cin cout

int main(){     //start of main() function body

int cur_num   = 1; // stores numbers

int stop_num= 100; // stops at this number which is 100

int total = 0;//stores the sum of 100 numbers

/* loop takes numbers one by one from cur_num variable and continues to add them until the stop_num that is 100 is reached*/

while (cur_num <= stop_num) {  

//keeps adding the numbers from 1 to 100

//increments value of cur_num by 1 at each iteration

 total += cur_num;

 cur_num = cur_num + 1; }  

//displays the sum of first 100 numbers

cout<<"The sum of first 100 numbers is: "<<total; }

The output is given in the attached screen shot.

You might be interested in
Which of these engine components forms a tight seal between the piston and the cylinder and is necessary for proper engine opera
TEA [102]
<h2>Piston rings help form a tight seal between the piston and cylinder.   Answer is A. Piston ring</h2>
5 0
3 years ago
Read 2 more answers
How does a cell phone change the<br> incoming signals from a caller into sound that<br> you can hear
shtirl [24]

Answer:

they send electrical signals to the buzzer. The buzzer changes those electrical signals into sound. You hear the buzzer sound and know that someone is calling you.

Explanation:

8 0
3 years ago
Read 2 more answers
What is income?
s2008m [1.1K]
I think its D hope this help
5 0
3 years ago
Read 2 more answers
When using the red / yellow / green method to present status of a project, yellow can mean which of the following? A. There are
DerKrebs [107]
It would be A. Think of radar for weather. Yellow splotches mean that it could get worse, but could get better. Hoped it helped!
5 0
3 years ago
Read 2 more answers
________ is a utility program included with most operating systems that allows you to move or eliminate files and give your oper
Sholpan [36]

Disk Defragmenter

A disk defragmenter is a utility that reorganizes the files and unused space on a computer's hard disk so that the operating system accesses data more quickly and programs run faster.

6 0
2 years ago
Other questions:
  • What aspect of the internet makes it fault-tolerant?
    6·1 answer
  • Dr. Patterson’s office calls to give patient Sara Martin her test results from her most recent visit. Her husband answers the ph
    8·2 answers
  • Create a detail report that will display all SCR courses in alphabetical order, with the course name and the instructor name in
    5·1 answer
  • In cryptography, the term "Secret algorithm" refers to an algorithm designed in a way that prevents the examination of its inner
    12·2 answers
  • In "When Is a Planet Not a Planet?" why does the author say that the outer planets are made of gas when the inner planets are ma
    5·1 answer
  • Select the correct answer.
    10·2 answers
  • PLEASE HELP!! WILL MARK BRAINLIEST!!
    9·1 answer
  • Me Completan Pliiiis
    10·2 answers
  • Which command os used to find a particular word in a document ?<br>​
    9·2 answers
  • What are the nuclear codes?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!