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

How were African Americans involved in the Revolutionary War? Who did they support and why?
Một doanh nghiệp trong thị trường cạnh tranh hoàn hảo có hàm tổng chi phí TC=100q2+50q+9. Giá và sản lượng đóng cửa của doanh nghiệp này là
Evaluate C=5/9(F−32) for F = 77 degrees.
Which of the following holds the least amount of carbon? Oceans Glaciers Plants Soil
what is the ordered pair to (-4,2)
What is the period of y=sin x
Part of the population of 6,750 elk at a wildlife preserve is infected with a parasite. A random sample of 50 elk shows that 3 of them are infected. How many el
The book of Philemon belongs to the section of the New Testament known as
PLS TELL ME HOW TO FIND THIS ANGLE
What is the percentage of 360grams of 6kg