Q:

Write a program that uses a while to sum the numbers from 50 to 100

0

Write a program that uses a while to sum the numbers from
50 to 100.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>

int main()
{
    int sum = 0, val = 50;
    while (val <= 100) {
        sum += val;
        ++val;
    }

    std::cout << "the sum is: " << sum << std::endl;

    return 0;
}

 

output:

the sum is: 3825

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now