Patey

Untitled

May 30th, 2020
956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. ofstream g("bac.txt");
  5. int main()
  6. {
  7.     int x,y,z,n,a[100],i,d1,d2,t=0,k;
  8.     cin>>n;
  9.     cin>>x;
  10.     cin>>y;
  11.     cin>>z;
  12.     a[1]=x;
  13.     a[2]=y;
  14.     a[3]=z;
  15.    d1=y-x;
  16.    d2=z-y;
  17.    if(n%2==1)
  18.         {
  19.             t=(n/2)*d2+(n/2)*d1+x;
  20.             k=1;
  21.         }
  22.     else
  23.         {
  24.             t=(n/2-1)*d2+(n/2)*d1+x;
  25.             k=0;
  26.         }
  27.    cout<<t<<" ";
  28.    while(n>1&&k==0)
  29.    {
  30.        if(x==0)
  31.        {
  32.            x=1;
  33.            t=t-d2;
  34.        }
  35.        else
  36.        {
  37.            x=0;
  38.            t=t-d1;
  39.        }
  40.        cout<<t<<" ";
  41.        n--;
  42.    }
  43.    while(n>1&&k==1)
  44.    {
  45.        if(x==0)
  46.        {
  47.            x=1;
  48.            t=t-d1;
  49.        }
  50.        else
  51.        {
  52.            x=0;
  53.            t=t-d2;
  54.        }
  55.        cout<<t<<" ";
  56.        n--;
  57.    }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment