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

When 20 gal of maple sap are boiled down,the result is 1/2 gal of maple syrup.how much sap is needed to produce a 9 gal of syrup?
Which was the first permanent English settlement in North America?
Who led movements to establish the Republic of Turkey? A. Aglar Baba B. Saad Zaghlul C. Mustafa Kemal D. Gamal Abdul Nasser
What times 3 equals 62
find the product. tell which strategy you used. 4X6x50
What is one half added to three quarters
Which was the first permanent English settlement in North America?
A bridge is 0.675 miles long. What is its length to the nearest hundredth of a mile
What is the whole number of 7/2?
Which document expresses that people are entitled to the free exercise of religion?