Ask Question

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);

+3
Answers (1)
  1. 26 March, 14:03
    0
    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “What is wrong with the following C+ + code? How would you fix it? int sum; for (int i=0; i ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers