Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <limits.h>
  4.  
  5. int len1(int x) {
  6.     int d = 0;
  7.     if (x == 0) return 1;
  8.     while (x > 0) {
  9.         x /= 10;
  10.         d++;
  11.     }
  12.     return d;
  13. }
  14.  
  15. void spaces1(int x) {
  16.     int i = 0;
  17.     for (i = 0; i < x; i++)
  18.         printf(" ");
  19. }
  20.  
  21. void tire1(int x) {
  22.     int i = 0;
  23.     for (i = 0; i < x; i++)
  24.         printf("-");
  25. }
  26.  
  27. int max1(int x, int y) {
  28.     if (x > y) return x;
  29.     else return y;
  30. }
  31.  
  32. int version1() {
  33.     int x, y;
  34.     printf("Vvedite dva natural'nih chisla\n");
  35.     scanf("%d %d", &x, &y);
  36.     if (x <= 0 || y <= 0) {
  37.         printf("\nNe vnaturi");
  38.         return 0;
  39.     }
  40.     if (x > INT_MAX / y || y > INT_MAX / x) {
  41.         printf("\nPerestaralsya malex");
  42.         return 0;
  43.     }
  44.     int dx, dy, ans = x * y;
  45.     dx = len1(x);
  46.     spaces1(20 - dx);
  47.     printf("%d\n", x);
  48.     dy = len1(y);
  49.     spaces1(20 - max1(dx, dy) - 1);
  50.     printf("x\n");
  51.     spaces1(20 - dy);
  52.     printf("%d\n", y);
  53.     int da = len1(ans);
  54.     spaces1(20 - da - dy + 1);
  55.     tire1(da + dy - 1);
  56.     printf("\n");
  57.     int i = 0;
  58.     while (1) {
  59.         int v = y % 10, d = len1(v * x);
  60.         spaces1(20 - d - i);
  61.         printf("%d", v * x);
  62.         spaces1(i);
  63.         printf("\n");
  64.         if (y / 10 == 0) {
  65.             spaces1(20 - da - i);
  66.             tire1(da + i);
  67.             printf("\n");
  68.             break;
  69.         }
  70.         /*
  71.         else
  72.         {                    //Mozhno ubrat'
  73.         spaces (20-d-i-2);
  74.         printf ("+\n");
  75.         }
  76.         */
  77.         y /= 10;
  78.         i++;
  79.     }
  80.     spaces1(20 - da);
  81.     printf("%d\n", ans);
  82.  
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement