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 latest new party formed in the united states in an election year was
The molecules responsible for membrane transport are
Functionalist psychologists focus on the function of behavior and ________.
How many calcium ions are there in caco3?
I need help with these two questions
Why is it impossible for a function to have fewer values in its domain than in its range?
Largest cryptocurrency country in the world
We refer to the bric nations as four global economic powers that will likely be important forces in world trade by 2030. it is predicted that the two nations th
Abe needs 13.5 feet to make a bedspread. How many yards does he need?
The sodium atom contains 11 electrons, 11 protons, and 12 neutrons. what is the mass number of sodium?