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 have a Nano Server named Nano1. Which cmdlet should you use to identify whether the DNS Server role is installed on Nano1
bija089 [108]

Answer:

The correct solution will be "Get-Package".

Explanation:

  • The accreditation property defines a domain as well as client initials with computer authorizations for executing commands. Mostly on the virtual device, the argument ScriptBlock executes the Get-Package cmdlet.
  • This order obtains from some kind of special introductory commercial software downloaded on either the user's computer.
5 0
3 years ago
The components of hardware include:
zlopas [31]

Answer:

A

Explanation:

Monitor, CPU, Disk Drives, Printer, Keyboard/mouse

5 0
3 years ago
Read 2 more answers
Rainfall_mi is a string that contains the average number of inches of rainfall in Michigan for every month (in inches) with ever
const2013 [10]

Answer:

Hi!

The answer in Javascript is:

function monthsWithMoreOfThree() {

  var Rainfall_mi = '3,4,1,5,2,6,7,9'; <em>//Defined and declared</em>

  var num_rainy_months = 0;

  var values = Rainfall_mi.split(","); <em>//use split method for Strings. Array is returned</em>

   for (var i = 0; i < values.length; i++) { <em>//for each value, compares with 3</em>

     if(values[i] > 3) { <em>//In Javascript, you can compare an String value with an int. Can use parseInt(aString) to explicit parse but is not necessary</em>

       num_rainy_months++; <em>//If value is greater than 3, adds 1 to num_rainy_months</em>

     }

   }

}

5 0
3 years ago
List the seven basic internal components found in a computer tower
egoroff_w [7]
1. Motherboard (you plug all other components to it)
2. Processor (CPU)
3. Memory (RAM)
4. Graphics card
5. Sound card (sometimes integrated with motherboard)
6. Hard Disk Drive (HDD)
7. Power supply unit
6 0
3 years ago
Read 2 more answers
The ip address 221.1.10.53 /24 is a what type of address?
jekas [21]
It is a class C address.  Class C covers all addresses in the range 192.0.0.0 to 223.0.0.0.  The /24 represents the number of network bits in the address so we can work out that the subnet mask of this address would be 255.255.255.0.
8 0
3 years ago
Other questions:
  • Briefly outline what LCD screen contain on the inside and why shouldn't it be opened by someone who is not qualified to work wit
    13·2 answers
  • Assume the following variable definitions int a = 5, b = 12; double x = 3.4, z = 9.1. What are the values of the following expre
    7·1 answer
  • Although you can use a dialog box to indent paragraphs, word provides a quicker way through the ____.
    7·1 answer
  • Why does my Office Computer send packet #1? What device responds by sending back packet #2? What information does my Office Comp
    15·1 answer
  • For this exercise, you'll use the Rectangle class below (you can assume that the length and width are measured in feet).
    12·1 answer
  • Which of the following languages does not provide built-in-pattern matching operations (the language, although, has pattern matc
    14·1 answer
  • Which iteration must have an expression that has a true or false value?
    11·2 answers
  • Explain how the organ systems work together to warm up the body on a cold day
    12·2 answers
  • Describe from an administrator perspective what is necessary to prepare a storage device for access by a user.
    14·1 answer
  • How has the widespread shift to remote work caused businesses to reconsider their use of Extended Reality (XR)?.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!