Program to calculate the sum of first 100 odd numbers using while loop
Using Visual Studio 2015
===============================================================
#include<iostream>
using namespace std;
#include<conio.h>
void main()
{
int x, num;
x = 0;
num = 1;
while (num <= 100)
{
if (num % 2 == 1)
{
x = num + x;
cout << num << " + ";
}
num++;
}
cout << "\nSum of first 100 odd numbers=" << x;
_getche();
}
=========================================================================
Comments
Post a Comment