"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Thursday, February 25, 2010

Write a C++ program to print the following series :

(i) 1  4   7  10   ......... 40
(ii) 1  -4  7  -10  ........ -40


#include<iostream.h>
#include<conio.h>
void main()
{
int a = 1, b = 1, i , incre = 3;

cout<<"\n The Series 1:";

for( i = 1 ; a<=40; i++)
{
cout<< a << " " ;
a = a+incre;
}

int p;

cout<<"\n The Series 2:";



for( i = 1 ; a<=40; i++)
{
if(i%2 == 0)
{p=-a;

cout<< p << " " ;
}
else
cout<< a << " ";

a = a+incre;
}
getch();

}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.