Summing integers with the for statement - C++ Statement

C++ examples for Statement:for

Description

Summing integers with the for statement

Demo Code

#include <iostream>

int main(int argc, const char *argv[]) {
    int total = 0;

    for (int number = 2; number <= 20; number += 2) {
        total += number;/* w  w w .ja  v  a2s .  co  m*/
    }

    std::cout << "Sum is " << total << std::endl;
    return 0;
}

Result


Related Tutorials