-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy path16.c
39 lines (32 loc) · 873 Bytes
/
16.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
// Function to compute GCD of two numbers using Euclidean algorithm
int gcd(int a, int b) {
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
int main() {
int n;
// Input the number of elements in the set
printf("Enter the number of elements in the set: ");
scanf("%d", &n);
int numbers[n];
// Input the elements in the set
printf("Enter the numbers in the set: ");
for (int i = 0; i < n; i++) {
scanf("%d", &numbers[i]);
}
// Find and print all coprime pairs
printf("Coprime pairs in the set are:\n");
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (gcd(numbers[i], numbers[j]) == 1) {
printf("(%d, %d)\n", numbers[i], numbers[j]);
}
}
}
return 0;
}