Program to calculate the sum of first 100 even numbers using while loop

Using Namespace Std:


=========================================================================
#include<iostream>
using namespace std;
#include<conio.h>
void main()

{

int x, num;

x = 0;

num = 1;

while (num <= 100)

{

if(num%2==0)

{

 x = num + x;
 
cout << num<< " + ";
 
}

 num++;

 }

cout << "\nSum of first 1000 even numbers=" << x;

_getche();
}




=========================================================================


Comments

Popular posts from this blog

Suppose you are given a square matrix of size n x n, write a program to determine if this is an identity matrix. 2D array

Program to create a multiplication table of a given number using while loop.

Program to find equal values using if statement in C++