Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include "locale.h"
- #include "math.h"
- // нахождения обьединение интервалов
- int uniteIntervals(int a, int b, int c, int d, int* e, int* f) {
- // идет проверка на то как находятся концы интервалов относительно друг друга
- if ((c <= b) && (a <= c )) {
- *e = c;
- if (d <= b) {
- *f = d;
- return 1;
- }
- *f = b;
- return 1;
- }
- else if ((a <= d) && (c <= a)) {
- *e = c;
- if (b <= d) {
- *f = d;
- return 1;
- }
- *f = b;
- return 1;
- }
- else
- return 0;
- }
- void main() {
- setlocale(LC_ALL, "rus");
- int a, b, c, d, e, f;
- printf("Введите интервал [a,b] и [c,d]: ");
- scanf_s("%d%d%d%d", &a, &b, &c, &d);
- if (uniteIntervals(a, b, c, d, &e, &f))
- printf("Обьединение интервалов = [%d,%d]", e, f);
- else
- printf("Обьединения нет.");
- if (uniteIntervals(a, b, c, d, &e, &f))
- printf("Обьединение интервалов = [%d,%d]", e, f);
- else
- printf("Обьединения нет.");
- if (uniteIntervals(a, b, c, d, &e, &f))
- printf("Обьединение интервалов = [%d,%d]", e, f);
- else
- printf("Обьединения нет.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement