Created
May 14, 2025 15:17
-
-
Save vlaleli/43dcb02e842ea9909805505eddda169c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() { | |
| const int n = 5; | |
| int A[n], B[n], C[n]; | |
| cout << "Enter the elements of array A: "; | |
| for (int i = 0; i < n; i++) | |
| { | |
| cin >> A[i]; | |
| } | |
| cout << "Enter the elements of array B: "; | |
| for (int i = 0; i < n; i++) | |
| { | |
| cin >> B[i]; | |
| } | |
| cout << "Enter the elements of array C: "; | |
| for (int i = 0; i < n; i++) | |
| { | |
| cin >> C[i]; | |
| } | |
| int result1[3 * n]; | |
| int index = 0; | |
| for (int i = 0; i < n; i++) | |
| { | |
| result1[index++] = A[i]; | |
| result1[index++] = B[i]; | |
| result1[index++] = C[i]; | |
| } | |
| cout << "Array with common values for A, B, C: "; | |
| for (int i = 0; i < 3 * n; i++) | |
| { | |
| cout << result1[i] << " "; | |
| } | |
| cout << endl; | |
| int result2[3 * n]; | |
| int result2_size = 0; | |
| for (int i = 0; i < n; i++) | |
| { | |
| bool found = false; | |
| for (int j = 0; j < result2_size; j++) | |
| { | |
| if (result2[j] == A[i]) | |
| { | |
| found = true; | |
| break; | |
| } | |
| } | |
| if (!found) | |
| { | |
| result2[result2_size++] = A[i]; | |
| } | |
| found = false; | |
| for (int j = 0; j < result2_size; j++) | |
| { | |
| if (result2[j] == B[i]) | |
| { | |
| found = true; | |
| break; | |
| } | |
| } | |
| if (!found) | |
| { | |
| result2[result2_size++] = B[i]; | |
| } | |
| found = false; | |
| for (int j = 0; j < result2_size; j++) | |
| { | |
| if (result2[j] == C[i]) { | |
| found = true; | |
| break; | |
| } | |
| } | |
| if (!found) | |
| { | |
| result2[result2_size++] = C[i]; | |
| } | |
| } | |
| cout << "Array with unique values for A, B, C: "; | |
| for (int i = 0; i < result2_size; i++) | |
| { | |
| cout << result2[i] << " "; | |
| } | |
| cout << endl; | |
| int result3[2 * n]; | |
| index = 0; | |
| for (int i = 0; i < n; i++) | |
| { | |
| result3[index++] = A[i]; | |
| result3[index++] = C[i]; | |
| } | |
| cout << "Array with common values for A and C: "; | |
| for (int i = 0; i < 2 * n; i++) | |
| { | |
| cout << result3[i] << " "; | |
| } | |
| cout << endl; | |
| int result4[3 * n]; | |
| int result4_size = 0; | |
| for (int i = 0; i < n; i++) | |
| { | |
| bool found = false; | |
| for (int j = 0; j < result4_size; j++) | |
| { | |
| if (result4[j] == A[i] || result4[j] == B[i] || result4[j] == C[i]) | |
| { | |
| found = true; | |
| break; | |
| } | |
| } | |
| if (!found) | |
| { | |
| if (A[i] != B[i] && B[i] != C[i] && A[i] != C[i]) | |
| { | |
| result4[result4_size++] = A[i]; | |
| result4[result4_size++] = B[i]; | |
| result4[result4_size++] = C[i]; | |
| } | |
| } | |
| } | |
| cout << "Array with distinct values for A, B, C without repetition: "; | |
| for (int i = 0; i < result4_size; i++) | |
| { | |
| cout << result4[i] << " "; | |
| } | |
| cout << endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment