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

The length of a rectangle is 6 centimeters and its area is [6x18] squere centimeters write an expression for the width
How many roots does the polynomial function, y=(x-8)(x+3)^2 have? A. 2 B. 4 C. 3 D. 1
How do I solve this equation: 14+3x=2+5x+4 ?
Steve and Ben have some money in their wallets. If Steve gives Ben $3, Ben will have twice as much as Steve. If Ben gives Steve $7, the amount Ben has will be o
Find the measure of z
What is a vector quantity? A. A quantity direction only B. A quantity with magnitude and direction C. A quantity with magnitude only D. A quantity with no magni
simplify 9^-5 x 9^-3
four fifths of senior class went to prom. if 324 seniors went to prom, how many are there in the senior class
how does the type of surface determine the amount of light reflected?
PLEASE HELP What do the Supreme Court decisions in the cases of Griswold v. Connecticut and Roe v. Wade have in common? A. limitations on executive privilege B.