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
fgiga [73]
3 years ago
6

Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have alre

ady been declared, use a while loop to compute the sum of the cubes of the first n counting numbers, and store this value in total. Thus if n equals 4, your code should put 1*1*1 2*2*2 3*3*3 4*4*4 into total. Use no variables other than n, k, and total. Do NOT modify n.
Computers and Technology
1 answer:
Fudgin [204]3 years ago
4 0

Answer:

The c++ program to implement the while loop is given below.

#include <iostream>

using namespace std;

int main() {

  // declaration of integer variables

   int k, n, total;

   // initialization of integer variables

   k=1, n=4, total=0;

//  loop executed till value of k becomes equal to value of n

   while( k <= n ){

       // cube of every integer is added to the variable total

       total = total + ( k * k * k );

       // value of k is incremented to go to the next number

k = k + 1 ;

   }  

   return 0;

}  

Explanation:

The program begins with the declaration of integer variables.  

int k, n, total;

This is followed by initialization of these variables.

k=1, n=4, total=0;

The while loop runs over the variable k which is initialized to 1. The loop runs till value of k reaches the value of integer n.

First, cube of k is computed and added to the variable total.

After first execution of the loop, total is initialized to the cube of 1.

Next, value of variable k is incremented by 1 so that k is initialized to next integer.

After first execution of the loop, k is incremented from 1 to 2.

while( k <= n )

{

total = total + ( k * k * k );

k = k + 1 ;

   }

When the value of k reaches the value of integer n, the cube of n is calculated and added to the variable, total.

When k is incremented, it becomes more than n and hence, loop gets terminated.

As the return type of main is int, the program terminates with the statement shown below.

return 0;

No output is displayed as it is not mentioned in the question.

No user input is taken as it is mentioned that integer variables are already initialized.

You might be interested in
You want to use a wireless keyboard and mouse with your laptop computer. which method should you use
Viefleur [7K]
If someone wants to use a wireless keyboard and mouse with a laptop computer, below are the steps.

First check if there’s a USB receiver attached to the mouse or keyboard. If there is, see below steps.

1. Connect the USB receiver of both mouse and keyboard into the USB port of your laptop computer. Some USB dongle would ask you to install or add it your device, just click OK and then add.
2. Make sure that the batteries on your wireless keyboard and mouse are working. And also check if the keyboard and mouse are turned on or have power.
3. Check if there’s a “connected” indication for both wireless mouse and keyboard on your laptop. You can now use your wireless mouse and keyboard on your laptop.

If there’s no USB receiver, and you’re using a bluetooth wireless mouse and keyboard, below are some steps to follow.

1. Turn on bluetooth connection on your laptop.
2. Make sure that batteries are working and turn on both wireless mouse and keyboard.
3. On your laptop, find your wireless mouse and keyboard under bluetooth option and connect the devices. You can now use your wireless bluetooth mouse and keyboard for laptop.
4 0
3 years ago
1). What is the proper name of the healing agent?
VLD [36.1K]

Answer:

1. Hydroxychloroquine is the healing agent

2. Chloroquine does not have a hydroxyl group attached    

Explanation:              

Chloroquine and  Hydroxy chloroquine have been in use for many decades for malaria treatment and prophylaxis.    

It was found that there was a high possibility of being poisoned when treatment of chloroquine was administered. In 1946 the hydroxyl group replaced the CH3₃  (methyl) group with an ⁻OH (hydroxyl) group as indicated by the attachment. Toxicity by chloroquine was reduced to 40% when the ⁻OH group was attached.

Later chloroquine was added to formulas that are used for cleaning pools and fish tanks.

Both of these chemicals should be used by following the guide lines and under medical supervision if taken for any illness.

3 0
3 years ago
In a word-processing program, what are the easily accessible icons that allow you to print, save and change fonts with a click o
Elan Coil [88]

The answer is A. tool bar

7 0
3 years ago
Giving brainliest if you answer question.
Maurinko [17]
The length of the inclined plane divided by the vertical rise, or you can call it run to rise ratio. The mechanical advantage would increase as the slope of the incline decreases, but problem is that the load will have to go a longer distance. The mechanical advantage would be slope of the incline. I also got confused on a question like this and did some research. Hope this helps!
4 0
3 years ago
It's possible to __________ out of a loop if the user has entered an incorrect value that would cause an error or a problem with
Stella [2.4K]

Answer:

The answer is Break

<u>Explanation:</u>

When break statement is occurred then, it immediately exits from the loop and executed the statement after the loop without raising any kind of error.

<u>The situation after entering of a value by a user </u>

  • If the user entered incorrect value then it will exit from the loop.
  • If the user entered correct input value, then it will run the loop for the further values.

4 0
3 years ago
Other questions:
  • In this assignment, you are going to add conditional formatting to the spreadsheet you used in the previous
    13·1 answer
  • Software that helps run the computer's hardware devices and coordinates instructions between applications is called
    10·1 answer
  • Help !!!!!
    9·1 answer
  • A word object in an excel worksheet to activate the word features
    9·1 answer
  • An algorithm written out in plain English statements is called __________.
    8·1 answer
  • What are the pasting options in Outlook 2016? Check all that apply.
    10·2 answers
  • A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. For example, the number 5 is prime be
    11·1 answer
  • 2. The<br>is the main and usually largest data storage hardware device in a computer​
    9·1 answer
  • Can somebody PLEASE help me cancel my subscription I have tried so many different things and contacted support - they are no hel
    14·1 answer
  • Assume that Publication is the root class of an inheritance tree. You want to form a linked list of different publications in th
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!