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
Lana71 [14]
4 years ago
12

Given that n refers to a positive integer, use a while loop to compute the sum of the cubes of the first n counting numbers, and

associate this value with total. Use no variables other than n, k, and total.
Computers and Technology
1 answer:
Rasek [7]4 years ago
6 0

Answer:

int k = 1;

int total = 0;

while (k <= n){

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

  k++;

}

Explanation:

The code above has been written in Java.

Following is the line-by-line explanation of the code written as comments.

// Initialize int variable k to 1.

// variable k is used to control the loop.

// It is initialized to 1 because the positive integers should start at 1.

// Starting at zero will be unimportant since the cube of 0 is still zero and

// has no effect on the overall sum of the cubes.

int k = 1;

// Initialize total to zero(0)

// This is so because, at the start of the addition total has no value.

// So giving it zero allows to cumulatively add other values to it.

// Variable <em>total </em>is also of type int because the sum of the cubes of counting

// numbers (which are positive integers) will also be an integer

int total = 0;

// Now create a while loop to repeatedly compute the sum of the cubes

// while incrementing the counter variable <em>k</em>.

// The condition for the loop to execute is when <em>k</em> is less than or equal to

// the value of variable <em>n.</em>

// The cube of any variable k is given by k^{3} which can be

// written as k * k * k.

// At every cycle of the loop, the cube of the counter <em>k</em> is calculated and

// added cumulatively to the value of <em>total</em>. The result is still stored in the

// variable <em>total. </em>After which <em>k</em> is incremented by 1 (k++).

while (k <= n) {

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

  k++;

}

You might be interested in
What are attributes and what role do they play with in a HTML document?
icang [17]

Answer:

HTML attributes are special words used inside the opening tag to control the element's behavior. HTML attributes are a modifier of an HTML element type. An attribute either modifies the default functionality of an element type or provides functionality to certain element types unable to function correctly without them.

Explanation:

5 0
4 years ago
10 points
Bingel [31]

Answer:

cool this is cool

Explanation:reEEEEEEE

6 0
3 years ago
Write a loop that prints each country's population in country_pop. Sample output with input:
Nostrana [21]

Answer:

  1. country_pop = {
  2.    'China': 1365830000,
  3.    'India': 1247220000,
  4.    'United States': 318463000,  
  5.    'Indonesia': 252164800
  6. }  
  7. for key in country_pop:
  8.    print(key + " has " + str(country_pop[key]) + " people")

Explanation:

The solution code is written in Python 3.

Given a dictionary, country_pop with data that includes four country along with their respective population (Line 1-6). We can use for in loop structure to traverse through each of the key (country) in the dictionary and print their respective population value (Line 7-8). The general loop structure through is as follow:

                    for key in dict:

                         do something

One key will be addressed for each round of loop and we can use that key to extract the corresponding value of the key (e.g. country_pop[key]) and print it out.

4 0
4 years ago
Which property of a DBMS lets you change the database structure without requiring you to change the programs that access the dat
Gala2k [10]

Answer:

"Integrity constraints " is the correct answer.

Explanation:

  • A successful DBMS offers integrity constraints, which have been an option that allows you to modify the database layout without modifying the applications accessing the repository.
  • A principle or requirement which the data in something like a database should therefore obey.

So that the above is the correct choice.

8 0
4 years ago
Consider the code fragment below (with nested loops). int sum = 0;for (int i = 1; i &lt; 5; i++) for (int j = 1; j &lt;= i; j++)
sammy [17]

Answer:

Option d is the correct answer for the above question.

Explanation:

  • The first loop of the program has a second loop and then the statement. In this scenario, the second loop executes for the value of the first loop and the statement executes for the value of the second loop.
  • The first loop executes 4 times, Then the second loop or inner loop executes n times for the n iteration of the first loop, for example, 1 time for the first iteration of the first loop, 2 times for the second iteration of the first loop and so on.
  • Then the inner loop executes (1+2+3+4) iteration which gives the result 10 iterations.
  • The sum initial value is 0 and the "sum++", increase the value of the sum by 1.
  • So the value of the sum becomes 10 after completing 10 iterations of the inner for loop.
  • Hence the 10 will be the output. So the Option d is the correct answer while the other is not.
3 0
3 years ago
Other questions:
  • Int, char, bool, and double are all valid data types in c , true or false
    15·1 answer
  • Someone who wants the credentials of skilled training, but in less time than a four-year degree should consider
    11·1 answer
  • In which type of land contract does the seller earn interest on the difference between what the seller owes on an existing loan
    14·1 answer
  • The _____ lets you see what styles have been applied to specific parts of a document, such as headings.
    9·1 answer
  • What binary number is the output of adding 1001011 and 100000?
    13·1 answer
  • What is the difference between the audio mixer and meters panel.
    8·1 answer
  • Which of the following is a negative effect of the rise in agricultural technology following World War II?
    5·1 answer
  • What is the depth of the following tree?
    10·1 answer
  • Similarities of ROM and RAM?​
    12·1 answer
  • Database policies should be created and implemented by all organizations, regardless of the ________ of the organization.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!