Advertisement
Guest User

ForMishaWithLove

a guest
Nov 20th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <locale.h>
  3. #include <stdlib.h>
  4.  
  5. int max(int a, int b)
  6. {
  7.     if ((a >= b))
  8.         return(a);
  9.     if ((b >= a))
  10.         return(b);
  11. }
  12. int min(int a, int b)
  13. {
  14.     if ((a <= b))
  15.         return(a);
  16.     if ((b <= a))
  17.         return(b);
  18. }
  19. int mod(int a, int b)
  20. {
  21.     if (a > 0)
  22.     {
  23.         a = a % b;
  24.         return a;
  25.     }
  26.     else
  27.     {
  28.         a = a % b + b;
  29.         return a;
  30.     }
  31. }
  32. int abs(int a)
  33.     {
  34.         if (a>0)
  35.         {
  36.             a=a;
  37.             return a;
  38.         }
  39.         else
  40.         {
  41.             a=-a;
  42.             return a;
  43.         }
  44.     }
  45.     int sign(int a)
  46.     {
  47.         if (a>0)
  48.         {
  49.             a=1;
  50.             return a;
  51.         }
  52.         if (a==0)
  53.         {
  54.             a=0;
  55.             return a;
  56.         }
  57.         if (a<1)
  58.         {
  59.             a=-1;
  60.             return a;
  61.         }
  62.     }
  63. int main()
  64. {
  65.     int x = 8, y = 15, l = 10, count = 0, x1 = 0, y1 = 0, l1 = 0,k=0;
  66.     while (count < 50)
  67.     {
  68.         x1 = ((x+y)*mod((abs(min(y-l,l-k))+1),20))+10;
  69.         y1 = min((x+y)/(2+sign(y*l-x*k)),(y+l)/(2+sign(x*y-l*k)))-10;
  70.         l1 =mod(max(x,y)*min(x,l),30);
  71.         count++;
  72.         x = x1;
  73.         y = y1;
  74.         l = l1;
  75.         k++;
  76.         if ((x>=-10) && (x<=0) && (y>=0) &&( y<=20))
  77.             break;
  78.     }
  79.     if (count < 50) {
  80.  
  81.  
  82.         setlocale(LC_ALL, "Rus");
  83.         printf("В цель попало\nвремя %d шаг\nx=%d\ny=%d\nl=%d\n", count, x, y, l);
  84.     }
  85.     else
  86.     {
  87.  
  88.  
  89.         setlocale(LC_ALL, "Rus");
  90.         printf("В цель не попал\nвремя окончания движения %d шаг\nx=%d\ny=%d\nl=%d\n", count+1, x, y, l);
  91.     }
  92.  
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement