Created
October 10, 2012 11:54
-
-
Save juanfal/3865150 to your computer and use it in GitHub Desktop.
for-loop sample. Summing up numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 03-12.forloopsum.cpp | |
#include <iostream> | |
using namespace std; | |
const int TOP = 1000; | |
int main() | |
{ | |
int sum = 0; | |
for (int n = 1; n <= TOP; n++) // Note that the variable n is a local | |
sum = sum + n; // variable of the body of the for loop! | |
cout << "The sum of the numbers 1 to " << TOP << " is " | |
<< sum << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment