Sunday, 9 October 2016

To print series 1,-4,7,-10..........

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int b=1,a;
cout<<"No. of terms = ";
cin>>a;
for(int i=1;i<=a;i++)
{
 if(i==1)
   { cout<<b<<"\n";
   }
 else
   { if (i%2==0)
{ b=b+3;
 b=b*(-1);
 cout<<b<<"\n";
}
     else
{ b=b*(-1);
 b=b+3;
 cout<<b<<"\n";
}
   }
}
getch();
}

No comments:

Post a Comment

Basic Implementation of Array as a Pointer

#include<iostream.h> #include<conio.h> void main() { clrscr();   int arr[5];   cout<<"Enter 5 nos. ";   f...