While 3

Same as While2 program but instead of summing only four terms you can summ up as many terms as you wish. 
// Controlstructure002.cpp : Defines the entry point for the console application.
// Find the solution for 2*a where nE[0,n]

#include "stdafx.h"
#include "iostream"
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
            int a, b, n;
            cout << "Enter the starting value of the sum (a): " << "\n";
            cin >> a;
            cout << " Enter maximum number of iterations :" << "\n";
            cin >> n;
            b=a;
            while(a < n){
                        ++a;
                        b += 2 * a;
            }
            cout << "The result of Sum(2*n) where nE[0," << n <<"] is: " << b << "\n";
            system("pause");
            return 0;

}
Share on Google Plus