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
A line of code that begins with the while needs to end which symbol?<br> # <br> "<br> :<br> .
olga_2 [115]
<h2>A line of code that begins with the "while" needs to end with <u>":"</u> symbol</h2>

Explanation:

In python, the while loop statement has ":" at the end of the line.

<u>Syntax:</u>

while expression:

code(s) or statement(s)

<u>Example:</u>

cnt = 0

while (cnt < 5):

  print 'cnt:', cnt

  cnt = cnt + 1

Like other programming languages, while loop works in the same way except that in python it comes alone with "else" statement. When the condition is false, "else" statement gets executed.

<u>Example:</u>

#!/usr/bin/python

cnt = 0

while cnt < 5:

  print cnt, " is  less than 5"

  cnt = cnt + 1

else:

  print cnt, " is not less than 5"

3 0
3 years ago
When is the following expression true? (2 points)
ipn [44]

Answer:

1) If and only if a and b have different values

Explanation:

Given

Expression: !(!a || b) || (!a && b)

Required

When is it true?

The expression is true when the values a and b are different and the proof is as follows.

(1) Assume that: a = true and b = false

!(!a || b) || (!a && b)  

= !(!true || false) || (!true && false)

!true = false, so the expression becomes:

= !(false|| false) || (false && false)

In boolean, false|| false = false and false && false = false. So, we have:

= !(false) || (false)

!(false) = true, so, the expression becomes:

= true || (false)

Lastly, true || false = true

(2) Assume that: a = false and b = true

!(!a || b) || (!a && b)  

= !(!false|| true) || (!false && true)

!false = true, so the expression becomes:

= !(true|| true) || (true && true)

In boolean, true|| true = true and true && true = true. So, we have:

= !(true) || (true)

!(true) = false, so, the expression becomes:

= false|| true

Lastly, false || true = true

<em>This expression is false if a and b have the same value</em>

4 0
3 years ago
Populate a stack with ten random integers and empty it by showing that the order of the elements is reversed, from last to first
Anuta_ua [19.1K]

Answer:

class Main {  

 public static void main(String args[]) {

   Deque<Integer> stack = new ArrayDeque<Integer>();

   Random rand = new Random();

   for(int i=0; i<10; i++) {

       int n = rand.nextInt(100);

       System.out.printf("%02d ", n);

       stack.push(n);

   }

   

   System.out.println();

   

   while(stack.size() > 0) {

       System.out.printf("%02d ", stack.removeFirst());

   }

 }

}

Explanation:

example output:

31 18 11 42 24 44 84 51 03 17  

17 03 51 84 44 24 42 11 18 31

4 0
3 years ago
What are the information ethics associated with IP
Naily [24]

Answer:

The IP stands for intellectual property. And the information ethics related to the IP are the transaction privacy, piracy and the privacy for the ease and giveaways, investigation, namelessness. The trade details must be kept private, and not disclosed to anybody, and the piracy is never allowed. Also, the privacy of all sorts must be ensured for ease and giveaways, surveillance, and confidentiality.

Explanation:

Please check the answer section.

3 0
4 years ago
What is not an example of ai
BARSIC [14]

Answer:

human

Explanation:

because it is not a machine

8 0
2 years ago
Read 2 more answers
Other questions:
  • Which of the following are unsponsored Internet domain extensions? .museum .gov .edu none of the above
    8·2 answers
  • Anyone want to talk?
    13·2 answers
  • The IT director instructed the systems administrator to build a server to support the accounting department's file growth. The I
    7·1 answer
  • The concept of algorithm ____, is one in which you can observe an algorithm being executed and watch as data values are dynamica
    7·1 answer
  • What are the role, responsibilities, and required background of the production designer of a film?
    6·1 answer
  • Peripheral are used to
    6·1 answer
  • During executing of the ______ PR task, units regain control of IP and transfer physical custody to the reintegration team.
    6·1 answer
  • Write one paragraph: Do you feel comfortable giving out personal information online? Why or why not? Is there a limit to what yo
    8·1 answer
  • The art element line is a moving point.<br><br><br> True or False
    15·1 answer
  • CSS At-rules provide a way for designers to define "if this, then that" scenarios.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!