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
Which tool should you use to modify firewall rules on a windows server?
vovikov84 [41]

Click Tools and select Windows Firewall with Advanced Security. Review the current configuration settings by selecting Windows Firewall Properties from the MMC landing page. You can access and modify the settings for each of the three firewall profiles, Domain, Private, and Public, as well as IPSec settings.

3 0
3 years ago
Can you edit header or footer? if yes, how​
DiKsa [7]

Answer:

It depends on the type of document you are trying to edit, but normally you can edit the header/footer.

Explanation:

For docs, you just double click near the top/bottom of the page.

8 0
2 years ago
Complete the sentence.
kogti [31]

Answer:

Release

Explanation:

4 0
2 years ago
Help Menu is available at which button in the keyboard?
kvasek [131]
Answer: It should be F1.
6 0
3 years ago
You are the IT security administrator for a small corporate network. You would like to use Group Policy to enforce settings for
LuckyWell [14K]

Answer/Explanation:

To Complete this lab, do the following:

1. From Server Manager, select Tools > Group Policy Management.

2. Expand Forest: CorpNet.com > Domains > CorpNet.com.

3. Right-click the OU where the policy will be linked and select Create a GPO in this domain, and link it here.

4. In the Name field, enter the GPO name; then click OK.

5. Link the GPO to additional OUs as follows:

a. Right-click the next OU and select Link an Existing GPO to link the GPO to another OU.

b. Under Group Policy objects, select Workstation Settings from the list; then click OK.

c. Repeat step 5 to link additional OUs.

6. Import a security policy template as follows:

a. Expand Group Policy Objects.

b. Right-click Workstation Settings and select Edit.

c. Under Computer Configuration, expand Policies > Windows Settings.

d. Right-click Security Settings and select Import Policy.

e. Browse to the C:\Templates.

f. Select ws_sec.inf; then click Open.

Cheers

3 0
2 years ago
Other questions:
  • Ron is creating building blocks in Word. How can he make the building blocks that he created available?
    11·2 answers
  • Describe what is meant by the following:
    14·1 answer
  • Dylan, an interior designer, has sketched out a layout for a client's living room. He wants the client's approval of the layout
    11·2 answers
  • What is the difference between a sequential program and an event-driven program?
    9·1 answer
  • Software applications called _____ provide the means to record information that passes through a computer or router that is hand
    10·1 answer
  • Where should your two index fingers be when your fingers are rest.
    14·1 answer
  • Use the function random.randint to write a program that rolls a 6-sided die 100 times, and prints out all of the rolls.
    8·1 answer
  • (50 points) Jeff wants to create a responsive web page where elements change size according to the size of the window. How would
    13·1 answer
  • Use the drop-down menus to complete each sentence.
    8·2 answers
  • Business use a fax cover sheet is to
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!