Braley6210 Braley6210
  • 03-10-2019
  • Computers and Technology
contestada

What is wrong with the following C++ code? How would you fix it? int sum; for (int i=0; i<1000; ++i) sum += i; { printf("Sum of 0 to 999 is %d\n", sum);

Respuesta :

SerenaBochenek SerenaBochenek
  • 05-10-2019

Answer:

Correct code is:

int sum;

  for (int i=0; i<1000; ++i)

  sum += i;

      printf("Sum of 0 to 999 is %d\n", sum);

Explanation:

In the problem code there is a open curly open bracket after the sum+=1;.

This open bracket will give an To fix this code, we remove this bracket from  the given code.Then this code will calculate sum of all number from 0 to 999.And the last line of the code will print the sum.

Answer Link

Otras preguntas

During digestion, why do you think it is necessary to break up the fat into tiny droplets?
How are square roots related to the area of a square ?
$1.06 what is it rounded to the nearest cent
One purpose of the Marshall Plan of 1948 was to (A) rebuild European economies to make communism less appealing (B) aid the depressed agricultural economies of
A square patio has an area of 200 square feet. How long is each side of the patio to the nearest tenth?
order from least to greatest 2.614; 2.146; 2.46; 2.164
The largest ethnic group in Nepal are the Bhote. true or false
which stage of a river development is characterized by flat floodplains
In French, our teacher has asked us to write a piece of writing where we sell our sibling on eBay. We have to describe them, and I can't figure it out?! Please
a company charges $46 for cable TV installation and $21 per month for basic cable service. Write an algebraic expression to represent the total cost of m months