Advertisement
Guest User

KI-19-1-20

a guest
Sep 17th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.06 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <math.h>
  6.  
  7. void print(int hr, int mn) {
  8.     char mas[40][40] = {0};
  9.     char rnd[40][81];
  10.     double x, y;
  11.  
  12.     for (int i = 0; i < 360; i += 30) {
  13.         x = sin(i*3.14 / 180.0)*15.0;
  14.         y = cos(i*3.14 / 180.0)*15.0;
  15.  
  16.         x += 20.5;
  17.         y += 20.5;
  18.  
  19.         mas[(int)x][(int)y] = 1;
  20.     }
  21.  
  22.  
  23.     hr *= 360 / 12;
  24.     hr += mn * 360 / 60 / 12;
  25.     hr -= 90;
  26.     for (double len = 0; len <= 8.0; len += 0.5) {
  27.         x = sin(hr*3.14 / 180.0)*len;
  28.         y = cos(hr*3.14 / 180.0)*len;
  29.  
  30.         x += 20.5;
  31.         y += 20.5;
  32.  
  33.  
  34.         mas[(int)x][(int)y] = 2;
  35.     }
  36.  
  37.     mn *= 360 / 60;
  38.     mn -= 90;
  39.     for (double len = 0; len <= 13.0; len += 0.5) {
  40.         x = sin(mn*3.14 / 180.0)*len;
  41.         y = cos(mn*3.14 / 180.0)*len;
  42.  
  43.         x += 20.5;
  44.         y += 20.5;
  45.  
  46.  
  47.         mas[(int)x][(int)y] = 2;
  48.     }
  49.  
  50.  
  51.     for (int i = 0; i < 40; i++) {
  52.         for (int j = 0; j < 40; j++) {
  53.             if (mas[i][j] == 1) {
  54.                 rnd[i][j * 2] = '-';
  55.                 rnd[i][j * 2 + 1] = '-';
  56.             }
  57.             else if (mas[i][j] == 2) {
  58.                 rnd[i][j * 2] = '*';
  59.                 rnd[i][j * 2 + 1] = '*';
  60.             }
  61.             else {
  62.                 rnd[i][j * 2] = ' ';
  63.                 rnd[i][j * 2 + 1] = ' ';
  64.             }
  65.            
  66.         }
  67.         rnd[i][80] = '\n';
  68.     }
  69.     rnd[39][80] = '\0';
  70.  
  71.     system("cls");
  72.     for (int i = 0; i < 40; i++) {
  73.         puts(rnd);
  74.     }
  75. }
  76.  
  77. double abs_dbl(double a) {
  78.     if (a < 0)
  79.         return -a;
  80.     return a;
  81. }
  82.  
  83. //4
  84. //-------------------------------------------------------
  85. void m_strcat(char* s, char* t, int n) {
  86.     int i = 0;
  87.     int j = 0;
  88.  
  89.     while (s[i] != '\0') {
  90.         i++;
  91.     }
  92.  
  93.     while (t[j] != '\0' && j < n) {
  94.         s[i] = t[j];
  95.         i++;
  96.         j++;
  97.     }
  98.  
  99.     s[i] = '\0';
  100. }
  101.  
  102. //5
  103. //-------------------------------------------------------
  104. int multiply(int a, int b) {
  105.     return multiply_r(a, b, 0);
  106. }
  107.  
  108. int multiply_r(int a, int n, int ans) {
  109.     if (n)
  110.         return multiply_r(a, --n, ans + a);
  111.     return ans;
  112. }
  113.  
  114. int main() {
  115.     int h = 0;
  116.     int m = 0;
  117.     int m_count = 0;
  118.  
  119.     printf("Hour: ");
  120.     scanf("%i", &h);
  121.  
  122.     printf("Min: ");
  123.     scanf("%i", &m);
  124.  
  125.     if (h >= 0 && h < 12 && m >= 0 && m < 60) {
  126.         print(h, m);
  127.         _getch();
  128.  
  129.         double h_ang = h * 360.0 / 12.0;
  130.         h_ang += m * 360.0 / 12.0 / 60.0;
  131.         double m_ang = m * 360.0 / 60.0;
  132.  
  133.         while (abs_dbl(h_ang - m_ang) > 360.0 / 60.0) {
  134.             m_count++;
  135.             m++;
  136.             if (m >= 60) {
  137.                 h++;
  138.                 m = 0;
  139.             }
  140.             if (h >= 12)
  141.             {
  142.                 h = 0;
  143.             }
  144.  
  145.             print(h, m);
  146.  
  147.             h_ang = h * 360.0 / 12.0;
  148.             h_ang += m * 360.0 / 12.0 / 60.0;
  149.  
  150.             m_ang = m * 360.0 / 60.0;
  151.  
  152.             //printf("\nAngle: %.2f", abs_dbl(h_ang - m_ang));
  153.  
  154.             Sleep(150);
  155.         }
  156.  
  157.         printf("%i hour %i minutes passed\n", m_count / 60, m_count % 60);
  158.     }
  159.     else {
  160.         printf("ERROR\n");
  161.     }
  162.  
  163.     _getch();
  164.  
  165.     system("cls");
  166.  
  167.     char s1[256], s2[256];
  168.     int n;
  169.  
  170.     printf("String 1: ");
  171.     scanf("%s", &s1);
  172.  
  173.     printf("String 2: ");
  174.     scanf("%s", &s2);
  175.  
  176.     printf("N: ");
  177.     scanf("%i", &n);
  178.  
  179.     m_strcat(s1, s2, n);
  180.  
  181.     printf("String result: %s\n", s1);
  182.    
  183.     _getch();
  184.  
  185.     system("cls");
  186.  
  187.  
  188.     int a, b;
  189.    
  190.     printf("A: ");
  191.     scanf("%i", &a);
  192.  
  193.     printf("B: ");
  194.     scanf("%i", &b);
  195.    
  196.     printf("%i * %i = %i\n", a, b, multiply(a, b));
  197.  
  198.     _getch();
  199.  
  200.     return 0;
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement