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

Expression: 7a²b + 362 Polynomial? Degree? Terms? Name? JUST NEED THE TERM
Brainliest What is the solution of the equation LaTeX: 3\left(x+2\right)=5x-2x+43 ( x + 2 ) = 5 x − 2 x + 4? Group of answer choices x= 3 x= 1 There is no solut
how did the expeditions of cortes and pizarro from those of other spanish explorers in the americas?
I NEED HELP WILL GIVE BRAINLIEST IF ALL ANSWERD
Then, when I saw Newton drinking it, I felt bold enough to cup my hand and drink a mouthful of water myself. It tasted like ambrosia. One sip was enough to wipe
if you were to make a restaurant, and need 29 items, how much of each would you have?
_____ can be described in many ways. A. Plasma B. State C. Matter D. Liquid
What are 4 domestic issues the United States faced?
What Does an E at the End of a Number Mean? in a calculator
PLEA HELP EASY QUESTION Who's the current head of the legislative branch