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
Archy [21]
4 years ago
8

Given int variables k and total that have already been declared, use a while loop to compute the sum of the squares of the first

50 counting numbers, and store this value in total. Thus your code should put 1*1 2*2 3*3 ... 49*49 50*50 into total. Use no variables other than k and total.
Computers and Technology
1 answer:
Bumek [7]4 years ago
8 0

Answer:

The c++ program for the given scenario is as follows.

#include <iostream>

using namespace std;

int main() {

   int k, total;

   k=1;

   total=0;

   while(k<=50)  

   {

// square of every counting number is added to total

       total = total + (k*k);

// value of k is incremented to move on to the next counting number

       k++;

   }

   cout<<"Sum of squares of first 50 counting numbers is " << total<<endl;

   return 0;

}

OUTPUT

Sum of squares of first 50 counting numbers is 42925

Explanation:

As mentioned, only two variables k and total are used in the program. These variables are declared with data type integer.

Variable k is initialized to 1 and variable total is initialized to 0.

k=1;

    total=0;

Variable k is used to represent counting number whose square is added to the variable total. Hence, values are taken accordingly.

The while loop is also known as the pre-test loop. This loop first evaluates the given condition and executes if the condition is satisfied.

   while(k<=50)  

The above while loop will execute till the value of variable k is less than or equal to 50. Once the value of k exceeds 50, the loop gets terminated. The loop executes 50 times, beginning from the value of 1 till k reaches 50.

The value of k is squared and added to the variable total each time the loop executes.

total = total + (k*k);

After the square is added to total, value of variable k is incremented by 1. This new value represents the next counting number.

k++;

After 50 executions of the loop, total variable will hold the sum of the squares of all the numbers from 1 to 50. The sum is displayed at the end.

This program implements the simplest logic for calculation of sum using two variables. The other loops such as for loop and do-while loop only differ in the placement and/or evaluation of the test condition.

You might be interested in
Do you think that dealing with big data demands high ethical regulations, accountability, and responsibility of the person as we
kicyunya [14]

Answer:

i will help you waiting

Explanation:

4 0
3 years ago
How do you change the top and bottom margins of an entire document
Elodia [21]
Deep depending on the document editor, you should be able to just click either the top or bottom margin to edit!
6 0
3 years ago
How is a ink pen better than a digital pen.
Hatshy [7]
It depends on what digital pen you're using.
Ink pens are better because they don't run out of ink like digital and you dont have to re-charge every time.
Hope this helps!:)<span />
8 0
3 years ago
using one sentence or phrase, how does each web version ( web 1.0, web 2.0, web 3.0 ) differ from one another?​
Mrrafil [7]
Web 1.0 connected people to information and Web 2.0 connected people to each other, both iterations were built on technology and products governed by centralized organizations and corporations. Web 3.0 connects information, people, and property, essentially digitizing trust through decentralized blockchain technology.

One sentence? Here goes:

Web 3.0 is the latest iteration of the Internet, designed learning the lessons and incorporating the features from 1.0 and 2.0, into a decentralized trust network.
3 0
2 years ago
- Truncate command response time is ______ as comparedto Delete command.
MArishka [77]

Answer:

c. Better

Explanation:

Truncate command response time is better as compared to Delete command.

8 0
3 years ago
Other questions:
  • When u look at a green object through red glass the object will appear
    11·2 answers
  • Explain the differences between kernel applications of the OS and the applications installed by an organization or user.
    6·1 answer
  • Return a version of the given string, where for every star (*) in the string the star and the chars immediately to its left and
    5·1 answer
  • You need to buy a cable to connect a desktop PC to a router. Which cable should
    13·1 answer
  • One major challenge in developing an international information system is to find​ a(n) ________ when there is so much cultural a
    11·1 answer
  • Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times
    8·1 answer
  • ITEMS
    9·1 answer
  • In Python, which comparison operator means "less than or equal to"?
    5·2 answers
  • Please help me on this it’s due now
    15·1 answer
  • Does anyone know how to permanently delete photos on a dell computer? For my cousin.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!