While 2

Write a program that sums 2*n numbers from 0 to 4.

// Controlstructure002.cpp : Defines the entry point for the console application.
// Find the solution for 2*n where nE[0,4]

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


int _tmain(int argc, _TCHAR* argv[])
{
            int a = 0, b = a, n = 4;
            while(a <= n){
                        ++a;
                        b += 2 * a;
            }
            cout << "The result of Sum(2*n) where nE[0,4] is: " << b << "\n";
            system("pause");
            return 0;
}


Share on Google Plus