
Write a C++ Program to display and sum of All Odd 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.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 = 1; counter <= number; counter+=2)
{
cout<<"\n \t"<<counter;
sum = sum + counter;
}
cout<<"\n\n The Sum of All Odd 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!