# The sum of the first n integer numbers [using “for”]

We are going to use a C++ program sequence in order to calculate the sum of the first “n” given positive integer numbers by using “for”:

#include

void main()

{

int n, sum=0;

cout<<"Give the last number which will be added to the sum"; cin>>n;

for (int i=0; i<=n; i++)

sum=sum+i;

cout<<"The sum of all the positive integers between 0 and "<< n <<" is "<< sum;

}

- The sum of the first positive n integer numbers [using “while”]
- The sum of the first n integer numbers [using “do while”]

Pingback: Retrospectiva săptămânii #1 : Cristi Juverdeanu