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
Archy [21]
4 years ago
8

Given int variables k and total that have already been declared, use a while loop to compute the sum of the squares of the first

50 counting numbers, and store this value in total. Thus your code should put 1*1 2*2 3*3 ... 49*49 50*50 into total. Use no variables other than k and total.
Computers and Technology
1 answer:
Bumek [7]4 years ago
8 0

Answer:

The c++ program for the given scenario is as follows.

#include <iostream>

using namespace std;

int main() {

   int k, total;

   k=1;

   total=0;

   while(k<=50)  

   {

// square of every counting number is added to total

       total = total + (k*k);

// value of k is incremented to move on to the next counting number

       k++;

   }

   cout<<"Sum of squares of first 50 counting numbers is " << total<<endl;

   return 0;

}

OUTPUT

Sum of squares of first 50 counting numbers is 42925

Explanation:

As mentioned, only two variables k and total are used in the program. These variables are declared with data type integer.

Variable k is initialized to 1 and variable total is initialized to 0.

k=1;

    total=0;

Variable k is used to represent counting number whose square is added to the variable total. Hence, values are taken accordingly.

The while loop is also known as the pre-test loop. This loop first evaluates the given condition and executes if the condition is satisfied.

   while(k<=50)  

The above while loop will execute till the value of variable k is less than or equal to 50. Once the value of k exceeds 50, the loop gets terminated. The loop executes 50 times, beginning from the value of 1 till k reaches 50.

The value of k is squared and added to the variable total each time the loop executes.

total = total + (k*k);

After the square is added to total, value of variable k is incremented by 1. This new value represents the next counting number.

k++;

After 50 executions of the loop, total variable will hold the sum of the squares of all the numbers from 1 to 50. The sum is displayed at the end.

This program implements the simplest logic for calculation of sum using two variables. The other loops such as for loop and do-while loop only differ in the placement and/or evaluation of the test condition.

You might be interested in
When each line of text hits the margin at the same point what is the text?
hoa [83]
When the text hits the margin, there is an invisible line that separates the texts.
4 0
3 years ago
Plz answer me will mark as brainliest​
tankabanditka [31]

Answer:

1.ALU

2.Barcode reader..

<h3>followme and mark me brainliest..........</h3>
5 0
3 years ago
What factor(s) should be considered when determining whether a business is too far based on the query and the user location? Sel
polet [3.4K]

Answer:

Type of Business/entity and User Location are True.

User Intent and your judgment are False.

Explanation:

The following are the factors that treated at the time of deciding the following business is based on the too far query and the location of the user. So, That's why the first two factors are applied by the type of business or entity and the location of the user but the last two factors are not applied because it is not about the user, it is related to the firm or the business.

7 0
3 years ago
A(n) ________ is the portion of virus code that is unique to a particular computer virus. A) virus signature B) encryptio
tino4ka555 [31]

Answer:

A) virus signature

Explanation:

Antivirus databases contain what are called signatures, a virus signature is a continuous sequence of bytes that is common for a certain malware sample.

--

Encryption is a way of scrambling data so that only authorized parties can understand the information.

7 0
2 years ago
Let S be an NP-complete problem and Q and R be two other problems not known to be in NP. Q is polynomial time reducible to S and
levacccp [35]

Answer:

B. R is NP Hard

Explanation:

Given:

S is an NP complete problem

Q is not known to be in NP

R is not known to be in NP

Q is polynomial times reducible to S

S is polynomial times reducible to R  

Solution:

NP complete problem has to be in both NP and NP-hard. A problem is NP hard if all problems in NP are polynomial time reducible to it.

Option B is correct because as given in the question S is an NP complete problem and S is polynomial times reducible to R.

Option A is not correct because R is not known to be in NP

Option C is not correct because Q is also not known to be in NP

Option D is not correct because Q because no NP-complete problem is polynomial time reducible to Q.

5 0
3 years ago
Other questions:
  • I only want someones opinion on this not anything you would find in a book.
    7·1 answer
  • All objects in an object-oriented program are instantiated (created) from a ____.
    12·1 answer
  • How much Continents Arctic Ocean that touches
    5·2 answers
  • Reversing the elements of an array involves swapping the corresponding elements of the array: the first with the last, the secon
    11·1 answer
  • Write a Program in C language using arrays:
    14·1 answer
  • 4-One possible performance multiplication enhancement is to do a shift and add instead of an actual multiplication. Since 9 * 6,
    12·1 answer
  • Give fields descriptive so that you can easily identify them when you view or edit records.
    13·1 answer
  • 1) If a robot has a 3 bit instruction set and needs 20 instructions to reach its destination, how many bits of memory are requir
    5·1 answer
  • area of trapezium is 54cmsq if parallel sides are 10cm and 8cm long find the distance between the parallel sides​
    12·1 answer
  • refer to the exhibit. a user pc has successfully transmitted packets to www.cisco. which ip address does the user pc target in o
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!