Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include <locale.h>
- #include <stdlib.h>
- int max(int a, int b)
- {
- if ((a >= b))
- return(a);
- if ((b >= a))
- return(b);
- }
- int min(int a, int b)
- {
- if ((a <= b))
- return(a);
- if ((b <= a))
- return(b);
- }
- int mod(int a, int b)
- {
- if (a > 0)
- {
- a = a % b;
- return a;
- }
- else
- {
- a = a % b + b;
- return a;
- }
- }
- int abs(int a)
- {
- if (a>0)
- {
- a=a;
- return a;
- }
- else
- {
- a=-a;
- return a;
- }
- }
- int sign(int a)
- {
- if (a>0)
- {
- a=1;
- return a;
- }
- if (a==0)
- {
- a=0;
- return a;
- }
- if (a<1)
- {
- a=-1;
- return a;
- }
- }
- int main()
- {
- int x = 8, y = 15, l = 10, count = 0, x1 = 0, y1 = 0, l1 = 0,k=0;
- while (count < 50)
- {
- x1 = ((x+y)*mod((abs(min(y-l,l-k))+1),20))+10;
- y1 = min((x+y)/(2+sign(y*l-x*k)),(y+l)/(2+sign(x*y-l*k)))-10;
- l1 =mod(max(x,y)*min(x,l),30);
- count++;
- x = x1;
- y = y1;
- l = l1;
- k++;
- if ((x>=-10) && (x<=0) && (y>=0) &&( y<=20))
- break;
- }
- if (count < 50) {
- setlocale(LC_ALL, "Rus");
- printf("В цель попало\nвремя %d шаг\nx=%d\ny=%d\nl=%d\n", count, x, y, l);
- }
- else
- {
- setlocale(LC_ALL, "Rus");
- printf("В цель не попал\nвремя окончания движения %d шаг\nx=%d\ny=%d\nl=%d\n", count+1, x, y, l);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement