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

what is the value of y?
The function f(x) = 1/5 is translated up 4 units. Which equation represents the translated function?
An operon encodes enzymes for making an essential amino acid and is regulated like the trp operon. Which of the statements is true?
M(5, 7) is the midpoint of rs The coordinates of S are (6, 9). What are the coordinates of R?
The Gulf Stream affects the climate of _____. Alaska California Great Britain Africa
What country restricts travel by American citizens to specific reasons like journalism and research?
In the following sentences, the verbs are in the passive voice. Rewrite each of the sentences, putting the verb in the active voice. Do not change the meaning
Food that needs to be reheated should be heated to a minimum internal temperature of A. 165 B. 100
What species dominate the forest?
Please help on this one!