Easyway how to write C++ Programs sum all even numbers from 1 to N |
Write a C++ Program to display and sum of All Even numbers from
1 to n (the entered positive number)by FOR Loop
For Free C++ Programming Techniques (Example Programs), visit
Www.EasyCppProgramming.Blogspot.Com
and For Good Notes
Visit www.ComputerGap.com
Www.ForFreeEducation.Blogspot.Com
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int number, counter;
long sum = 0;
cout<<"\n Enter a positive number = ";
cin>>number;
cout<<"\n\n ----------- Results ------------";
cout<<"\n\n All Even Numbers between \n 1 to n(entered positive number)\n by For Loop ";
for (counter = 2; counter <= number; counter+=2)
{
cout<<"\n \t"<<counter;
sum = sum + counter;
}
cout<<"\n\n The Sum of All Even Numbers between \n 1 to n(entered positive number)\n by For Loop ="<<sum;
getch();
}
0 comments:
Post a Comment
We Love To Hear From You!