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

Please Help!! Brainliest Answer! Thank you
What is the measure of angle SAR?
If 20 squirrels can eat a bushel of corn in 10 hours, how many squirrels can eat a bushel of corn in 2 hours?
Solve for h. h + 1 = 10 h. Submit
FOCUS QUESTION Why do elements in the same group have similar properties?
Compare the three equation and make a statement to describe them
Which expression can be used to calculate the expression 56 ÷516 for 100 points and brainliest
Marry finished her sending assignment: what are the parts of speech
Which is NOT an example of active transport BRAINLIEST Osmosis Membrane pumps Exocytosis Endocytosis
Poème : L’Horloge, Charles Baudelaire. 1. Comment se présente le poème ? (forme : strophes, mètre, rimes) 2. Quel est le registre dominant ? Justifie