Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- { // Harel Levy
- //203677836
- //8911003
- // Exercise 1
- int row,column,length,start_pos,step,speed;
- int i,j,k;
- int hekef,hekef_1_2,hekef_3_4,hekef_1_4;
- char char_to_print;
- char plus='+';
- char minus='-';
- char mul='*';
- char anach='|';
- char equal='=';
- int mikum_in_misgeret;
- int row_mikum,column_mikum;
- int snake_length;
- int next_step;
- int org_row,org_column;
- scanf("%d%d%d%d%d%d",&column,&row,&length,&start_pos,&step,&speed);
- /* set size of parameters of recatangle*/
- hekef_1_4=column-1;
- hekef_1_2=row+column-2;
- hekef_3_4=2*(column-1)+row-1;
- hekef=(row-1)*2+(column-1)*2;
- /*set position for jumping in the rectangle*/
- org_row=row;
- org_column=column;
- mikum_in_misgeret=start_pos;
- next_step=start_pos;
- //start program
- for(k=0;k<step+1;k++)
- {
- printf("%d\n",k);
- //set start print for the next time ,not for the first time
- if(k!=0)
- {
- next_step+=speed;
- //find if we are over the hekef of recatangle
- if(next_step>hekef) next_step = next_step - hekef;
- mikum_in_misgeret=next_step;
- }
- snake_length=length; //set snake legth for calcaulting progressing
- for(i=0;i<row;i++)
- {
- for(j=0;j<column;j++)
- {
- //find where we are in the hekef of misgeret
- if(mikum_in_misgeret<=hekef_1_4) //we are in the first row withnin misgeret
- {
- row_mikum=0;
- column_mikum=mikum_in_misgeret;
- }
- if(mikum_in_misgeret>hekef_1_4) //we are in the last column withnion misgeret
- {
- row_mikum=mikum_in_misgeret-hekef_1_4;
- column_mikum=hekef_1_4;
- }
- if(mikum_in_misgeret>hekef_1_2)
- {
- row_mikum=org_row-1;
- column_mikum=hekef_3_4-mikum_in_misgeret;
- }
- if(mikum_in_misgeret>hekef_3_4)
- {
- row_mikum=hekef-mikum_in_misgeret;
- column_mikum=0;
- }
- //find if we are withnin the misgeret find if we sould print +/=
- if((i==row_mikum)&&(j==column_mikum))
- {
- if((snake_length%2)==0)
- {
- printf("%c",plus);
- }
- if((snake_length%2)==1)
- {
- printf("%c",equal);
- }
- snake_length=snake_length - 1;
- if(snake_length==0)
- continue;
- else
- {
- mikum_in_misgeret++;
- //find if we are in the end of recatangle
- if(mikum_in_misgeret==hekef)
- mikum_in_misgeret=0;
- continue;
- }
- } //end if
- //now print | or -
- if((i==0)||(i==org_row-1))
- {
- printf("%c",minus);
- continue;
- }
- if((j==0)||(j==org_column-1))
- {
- printf("%c",anach);
- continue;
- }
- if(((j!=0)||(j!=org_column-1))&&((i!=0)||(i!=org_row-1)))
- {
- printf("%c",mul);
- continue;
- }
- }
- printf("\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement