By using a C++ program, we are going to determine the sum of the first “n” positive integers as we use the “do whil”e structure:
#include
void main()
{
int n, sum=0;
cout<<"Give the last number which will be added to the sum"; cin>>n;
do {
sum=sum+n;
n--;} while (n>0);
cout<<"The given sum is"<< sum;
}
The post The sum of the first n integer numbers [using “do while”] appeared first on BorlandC.org.