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

HELP HELP HELP HELP PLEASE (sorry ) can u complete this tiny is to .................. as broad is to ........................ the words to fill this in are tiny
1. What is the value of the expression below? Please show work 3⁴+9= A.21 B.39 C.43 D.90 2. Which expression is equivalent to 5(d+1)? Please show work A.5d+5 B.
PLEASE CHECK MY ANSWERS (PART 2)
THE FULL MOON TURNED ORANGE AND THEN GOT REALLY DARK WHAT COULD HAVE MADE IT TURN DARK LIKE THAT
A sand box has an area of 45 ft. The length is 4 feet longer than the width. What are the dimensions of the sand box? Solve by completing the square
why did many aristocrats support legalism
why did farmers follow railroads into the texas frontier
which of the following did not trigger Haiti's fight for independence
What is the prefix of active
1) Elizabeth works part-time to help pay for college. She has worked for the last 14 days without a day off for a total of 48 hours. Depending on her schedu