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
. Create an abstract Dollar class with two integer attributes, both of which are non-public (Python programmers - it is understo
aksik [14]

Answer:

Explanation:

The following code is written in Java. It creates the abstract dollar class that has two instance variables for the dollars and the coins that are passed as arguments. The test output can be seen in the picture attached below.

class Dollar {

   int dollars;

   double coin;

   private Dollar(int dollar, int coin) {

       this.dollars = dollar;

       this.coin = Double.valueOf(coin) / 100;

   }

   

}

4 0
3 years ago
Describe one way that cells use water
antiseptic1488 [7]
In chemical reactions, as a carrier of materials or keeping the temperature of cells from quickly changing.
8 0
3 years ago
PLZ HELP IM DOING 2 other 100 work and I’m running out of time for school 1. Imagine you are a screenplay writer Discuss some po
Alexus [3.1K]
My mans this is to long to read ); I got u tho lemme pick
5 0
3 years ago
Which statement describe the advantages of using XML? more than one answer can be correct
Sveta_85 [38]

Answer:

The statements that describe the advantages of using XML are;

B-It allows for data storage in a separate file

D-It is software independent

E-It facilitates the transport of data

Explanation:

XML data can be stored in separate file such that the layout and display can designed in HTML whereby the data in the XML file can be changed without changing the HTML

XML is both software and hardware independent thereby it is possible to use the same XML to carry information to different computers and software

XML is used for data transport.

6 0
3 years ago
Which of the following is a correct method header for receiving a two-dimensional array as an argument?A.public static void pass
allochka39001 [22]

Answer:

The correct option for this question is "B".

Explanation:

An Array is a collection of the homogenous(same type) elements. In the programming language, the correct way to pass two-dimensional array in function as an argument is option "B" and other options are not correct that can be described as:

  • In option, A It is a one-dimensional array but it is not a correct way to pass array in an argument like this.
  • In option, C It is a two-dimensional array but in this array, we do not pass any number.
  • In option, D it is not a two-dimensional array.    

That's why the answer to this question is option "B".

3 0
3 years ago
Other questions:
  • Why are prepositions, conjunctions, and pronouns usually considered poor choices to use as key words?
    5·2 answers
  • True or Flase<br><br> In C++, the body of a for loop may never run even once.
    15·1 answer
  • Here's a thought: Why does your Brainly ranking keep going down?
    6·2 answers
  • Which speaker port should you use when connecting a single speaker to a pc?
    6·1 answer
  • What is the name of the program file that you can enter in the Windows search or Run box to execute Event Viewer? What process i
    12·1 answer
  • Can you use public domain images without violating copyright laws?
    5·1 answer
  • Can some please help me learn how to make a program via Binary Code?
    7·1 answer
  • What is the purpose of the Occupational Safety and Health Act?
    7·2 answers
  • What is DMTS. Explain it​
    10·2 answers
  • Missing appropriate security hardening across any part of the application stack or improperly configured permissions is an examp
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!