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; }
The post The sum of the first positive n integer numbers [using “while”] appeared first on BorlandC.org.