fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main() {
  5. // Множина A = { x ∈ Z | -3 ≤ x ≤ 3 }
  6. int A_min = -3, A_max = 3;
  7.  
  8. // Множина B = { y ∈ N | -6 ≤ y ≤ 6 }
  9. // N — натуральні числа → 1,2,3,... але іноді включають 0
  10. // Тут візьмемо 0..6 (бо -6..-1 не входять)
  11. int B_min = 0, B_max = 6;
  12.  
  13. printf("Множина A = { ");
  14. for (int x = A_min; x <= A_max; x++) printf("%d ", x);
  15. printf("}\n");
  16.  
  17. printf("Множина B = { ");
  18. for (int y = B_min; y <= B_max; y++) printf("%d ", y);
  19. printf("}\n\n");
  20.  
  21. printf("Відношення P1 = { (x, y) | x ∈ A, y ∈ B, |x - y| ≤ 3 }\n\n");
  22. printf("Елементи P1:\n");
  23.  
  24. for (int x = A_min; x <= A_max; x++) {
  25. for (int y = B_min; y <= B_max; y++) {
  26. if (abs(x - y) <= 3) {
  27. printf("(%d, %d)\n", x, y);
  28. }
  29. }
  30. }
  31.  
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
Множина A = { -3 -2 -1 0 1 2 3 }
Множина B = { 0 1 2 3 4 5 6 }

Відношення P1 = { (x, y) | x ∈ A, y ∈ B, |x - y| ≤ 3 }

Елементи P1:
(-3, 0)
(-2, 0)
(-2, 1)
(-1, 0)
(-1, 1)
(-1, 2)
(0, 0)
(0, 1)
(0, 2)
(0, 3)
(1, 0)
(1, 1)
(1, 2)
(1, 3)
(1, 4)
(2, 0)
(2, 1)
(2, 2)
(2, 3)
(2, 4)
(2, 5)
(3, 0)
(3, 1)
(3, 2)
(3, 3)
(3, 4)
(3, 5)
(3, 6)