(i) 1 4 7 10 ......... 40
(ii) 1 -4 7 -10 ........ -40
{
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();
}
(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