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

The idea of the following sequence is to create a C++ function which will calculate the sum of all the positive numbers from 0 to a user defined number (n).

#include void main() { int n, sum=0, a; cout<<"Give the last number which will be added to the sum"; cin>>n; a=n; while (n>0) { sum=sum+n; n--; } cout<<"The sum of all the positive integers between 0 to "<< a <<" is "<< sum; }

- Installing Borland C++ on dosBox: The solution for “too many subdirectories press esc”
- The sum of the first n integer numbers [using “for”]

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