Q:

Write your own version of a program that prints the sum of a set of integers read from cin

0

Write your own version of a program that prints the sum of a set of integers read from cin.

All Answers

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

#include <iostream>

int main() {
  std::cout << "Enter numbers:" << std::endl;
  int sum = 0, val = 0;
  while (std::cin >> val)
    sum += val;
  std::cout << "The sum of numbers is " << sum << std::endl;
  return 0;
}

 

Output:

3 4 5 6
Sum is: 18

 

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