C++ examples for Statement:for
Using a for statement to sum a sequence of integers.
#include <iostream> int main(int argc, const char *argv[]) { int limit, num, total = 0; std::cout << "Enter number of values to be summed followed by values: "; std::cin >> limit;/*from w w w.j av a 2 s .c om*/ for (int i = 1; i <= limit; i++) { std::cin >> num; total += num; } std::cout << "Total = " << total << std::endl; return 0; }