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
Explain the concept of scalability. How would you respond?
pantera1 [17]

Answer:

In computer science, scalability is the ability of an application or product that could be software or software to continue responding well when its context is increased in volume or size to meet the user demand. Typically, when a product becomes aging or the context demands a rescaling to a larger size or volume, if the product is prepared to respond to this demand, then it's called a scalable product.

6 0
3 years ago
Name the contributions of Steve Jobs and Bill Gates, with respect to technology.
Sergio [31]

Answer: Steve Jobs made several contributions towards technology by introducing the range of Apple devices and technologies .he started the Apple Incorporation.The technologies introduced by his company are as follows:-

  • iPod
  • iPhone
  • Apple Lisa
  • iMac
  • iPad etc.

 Bill Gates is the founder of Microsoft incorporation and made a lot of development in that field to create various software for the operating system.the creation of "Microsoft Window" was started by him and some other contributions are as follows:

  • Windows 7
  • Windows 8
  • Vista
  • XP
  • windows 95 etc.
3 0
4 years ago
What runs horizontally and is identified with numbers?
kramer
D. the answer is Column 
6 0
3 years ago
Read 2 more answers
Polynomial regression A common misconception is that linear regression can only be used to fit a linear relationship. We can fit
3241004551 [841]

Answer:

robuk plss55 5=5

Explanation:

just 5 pawpatrol

8 0
2 years ago
Briefly describe the interface between the memory and the processing unit. That is, describe the method by which the memory and
xxMikexx [17]

Answer:

The memory and the processing unit communicate through the Memory Address Register (MAR) and the Memory Data Register (MDR).

Explanation:

7 0
4 years ago
Other questions:
  • In a relational database design, all relationships are expressed by ________.
    10·1 answer
  • Write a function called median, that takes as parameter a full, sorted array of doubles and returns the median of the list. For
    15·1 answer
  • The Middle East links which two countries
    10·2 answers
  • How do i cancle my account on brainly
    11·1 answer
  • There is a company of name "Baga" and it produces differenty kinds of mobiles. Below is the list of model name of the moble and
    7·1 answer
  • Give two examples of html structure
    15·1 answer
  • If i hit the delete key three times what will be left
    12·1 answer
  • Please tell me which ones go into which categories no files!!
    11·1 answer
  • In what ways can you modify the location of the neutral point?
    12·1 answer
  • 15. It is the process of capturing data or translating information to recording format
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!