Sunday, 16 October 2016

HHW Q33A. WAP to print series 1,-4,7,-10.....

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=1,b,c,n;
cout<<"Enter the no. of terms ";
cin>>n;
for (int i=1;i<=n;i++)
{ if (i==1)
     { cout<<a<<"\n";
     }
  else
     { if (i%2==0)
 { a=a+3;
   a=a*(-1);
   cout<<a<<"\n";
 }
       else
 { a=a*(-1);
   a=a+3;
   cout<<a<<"\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...