Advertisement
AnAriyan

Series a01/a02

Feb 9th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class Series {
  4. private:
  5.     int n,i,sum=0,a=2,b=0;
  6. public:
  7.  
  8. void input () {
  9. cout<<"Enter series Length : ";
  10. cin>>n;
  11.  
  12. }
  13. void Series1 () {
  14.     cout<<endl;
  15.       cout<<"Series 1 : "<<endl;
  16.     cout<<"1+ 2 + ";
  17.  
  18. for(i=2;i<=n;i++) {
  19.  
  20.    b=a+i;
  21.    a=b;
  22. sum=sum+b;
  23.  cout<<b<<" + ";
  24.     //sum=sum+i;
  25.  
  26.  
  27.     }
  28.    cout<<"\b\b = "<<sum+1+2<<endl;
  29.  }
  30.  void series2(){
  31.      cout<<endl;
  32.      cout<<"Series 2 : "<<endl;
  33.  for (int i=1; i<n;i++)
  34.  {
  35.      if(i%2!=0)
  36.      {
  37.          cout<<i<<" ";
  38.      }
  39.      else
  40.         cout<<i*2<<" ";
  41.  }
  42.  
  43.  }
  44.  
  45. };
  46. int main()
  47. {
  48.  
  49.     Series obj;
  50.     obj.input();
  51.     obj.Series1();
  52.     obj.series2();
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement