Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.72 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. { // Harel Levy
  4.  //203677836
  5.  //8911003
  6. // Exercise 1
  7.     int row,column,length,start_pos,step,speed;
  8.     int i,j,k;
  9.     int hekef,hekef_1_2,hekef_3_4,hekef_1_4;
  10.     char char_to_print;
  11.     char plus='+';
  12.     char minus='-';
  13.     char mul='*';
  14.     char anach='|';
  15.     char equal='=';
  16.     int mikum_in_misgeret;
  17.     int row_mikum,column_mikum;
  18.     int snake_length;
  19.     int next_step;
  20.     int org_row,org_column;
  21.     scanf("%d%d%d%d%d%d",&column,&row,&length,&start_pos,&step,&speed);
  22.     /* set size of parameters of recatangle*/
  23.     hekef_1_4=column-1;
  24.     hekef_1_2=row+column-2;
  25.     hekef_3_4=2*(column-1)+row-1;
  26.     hekef=(row-1)*2+(column-1)*2;
  27.     /*set position for jumping in the rectangle*/
  28.     org_row=row;
  29.     org_column=column;
  30.     mikum_in_misgeret=start_pos;
  31.     next_step=start_pos;
  32.     //start program
  33.     for(k=0;k<step+1;k++)
  34.     {
  35.         printf("%d\n",k);
  36.         //set start print for the next time ,not for the first time
  37.         if(k!=0)
  38.         {
  39.             next_step+=speed;
  40.             //find if we are over the hekef of recatangle
  41.             if(next_step>hekef) next_step = next_step - hekef;
  42.             mikum_in_misgeret=next_step;
  43.         }
  44.         snake_length=length;        //set snake legth for calcaulting progressing
  45.         for(i=0;i<row;i++)
  46.         {
  47.             for(j=0;j<column;j++)
  48.             {
  49.                 //find where we are in the hekef of misgeret
  50.                 if(mikum_in_misgeret<=hekef_1_4)  //we are in the first row withnin misgeret
  51.                 {
  52.                     row_mikum=0;
  53.                     column_mikum=mikum_in_misgeret;
  54.                 }
  55.                 if(mikum_in_misgeret>hekef_1_4) //we are in the last column withnion misgeret
  56.                 {
  57.                     row_mikum=mikum_in_misgeret-hekef_1_4;
  58.                     column_mikum=hekef_1_4;
  59.                 }
  60.                 if(mikum_in_misgeret>hekef_1_2)
  61.                 {
  62.                     row_mikum=org_row-1;
  63.                     column_mikum=hekef_3_4-mikum_in_misgeret;
  64.                    
  65.                 }
  66.                 if(mikum_in_misgeret>hekef_3_4)
  67.                 {
  68.                     row_mikum=hekef-mikum_in_misgeret;
  69.                     column_mikum=0;
  70.                 }
  71.             //find if we are withnin the misgeret find if we sould print +/=
  72.                 if((i==row_mikum)&&(j==column_mikum))
  73.                 {
  74.                     if((snake_length%2)==0)
  75.                     {
  76.                         printf("%c",plus);
  77.                     }
  78.                     if((snake_length%2)==1)
  79.                     {
  80.                         printf("%c",equal);
  81.                     }
  82.                     snake_length=snake_length - 1;
  83.                     if(snake_length==0)
  84.                         continue;
  85.                     else
  86.                     {
  87.                         mikum_in_misgeret++;
  88.                         //find if we are in the end of recatangle
  89.                         if(mikum_in_misgeret==hekef)
  90.                             mikum_in_misgeret=0;
  91.                         continue;
  92.                     }
  93.                 } //end if
  94.                     //now print | or -
  95.                     if((i==0)||(i==org_row-1))
  96.                     {
  97.                         printf("%c",minus);
  98.                         continue;
  99.                     }
  100.                     if((j==0)||(j==org_column-1))
  101.                     {
  102.                         printf("%c",anach);
  103.                         continue;
  104.                     }
  105.                     if(((j!=0)||(j!=org_column-1))&&((i!=0)||(i!=org_row-1)))
  106.                     {
  107.                         printf("%c",mul);
  108.                         continue;
  109.                     }
  110.                 }
  111.                 printf("\n");
  112.             }
  113.         }
  114.  
  115.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement