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

A corporation issued 2,500 shares of its no par common stock at a cash price of $11 per share. The entry to record this transaction would be:
hey guys a have wut is 2xA(19x56)Ax12 thanks if u can help me
please help : x^3-57x+56 by x-7​
Which of the following occurred during the Boston Massacre in 1770? A. The Royal Governor resigned his position. B. John Adams read the Declaration of Independe
How will you show that metals form basic oxides?​
Ben's earnings for work he did from Monday through Saturday were: $78, $94, $115, $108, $67, $78. What was his average daily pay for the days he worked?
Determine the zeros of the function f(x) = (x - 2)(x + 2)(x+1)^2
a group of 6 people equally shares 12 Liters of juice, how many milliliters of juice does each person recive
someone help.me find angle C and Dalso this is in CIRCLE THEOREM lesson​
Bacteria and fungal spores can only contribute to indoor air pollution. a/True b/False​