Advertisement
Qellex

4.1

Dec 17th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "locale.h"
  3. #include "math.h"
  4.  
  5. // нахождения обьединение интервалов
  6. int uniteIntervals(int a, int b, int c, int d, int* e, int* f) {
  7.     // идет проверка на то как находятся концы интервалов относительно друг друга
  8.     if ((c <= b) && (a <= c )) {
  9.         *e = c;
  10.         if (d <= b) {
  11.             *f = d;
  12.             return 1;
  13.         }
  14.         *f = b;
  15.         return 1;
  16.     }
  17.     else if ((a <= d) && (c <= a)) {
  18.         *e = c;
  19.         if (b <= d) {
  20.             *f = d;
  21.             return 1;
  22.         }
  23.         *f = b;
  24.         return 1;
  25.     }
  26.     else
  27.         return 0;
  28. }
  29.  
  30.  
  31. void main() {
  32.  
  33.     setlocale(LC_ALL, "rus");
  34.  
  35.     int a, b, c, d, e, f;
  36.  
  37.     printf("Введите интервал [a,b] и [c,d]: ");
  38.     scanf_s("%d%d%d%d", &a, &b, &c, &d);
  39.  
  40.     if (uniteIntervals(a, b, c, d, &e, &f))
  41.         printf("Обьединение интервалов = [%d,%d]", e, f);
  42.     else
  43.         printf("Обьединения нет.");  
  44.  
  45.     if (uniteIntervals(a, b, c, d, &e, &f))
  46.         printf("Обьединение интервалов = [%d,%d]", e, f);
  47.         else
  48.         printf("Обьединения нет.");    
  49.  
  50.     if (uniteIntervals(a, b, c, d, &e, &f))
  51.         printf("Обьединение интервалов = [%d,%d]", e, f);
  52.         else
  53.         printf("Обьединения нет.");
  54.  
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement