2, 3, 4, 5, 6, 1, 2, 3, 4
5, 6, 1
#include <stdio.h>
void printDistinctElements(int arr[], int size) {
printf("Distinct elements in the array are: ");
for (int i = 0; i < size; i++) {
int isDistinct = 1;
for (int j = 0; j < size; j++) {
if (arr[i] == arr[j] && i != j) {
isDistinct = 0;
break;
}
}
if (isDistinct) {
printf("%d ", arr[i]);
}
}
printf("\n");
}
int main() {
int n;
// Input size of the array
printf("Enter the size of the array: ");
scanf("%d", &n);
int arr[n];
// Input array elements
printf("Enter %d elements of the array: ", n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
// Print distinct elements
printDistinctElements(arr, n);
return 0;
}
Sample Input:Enter the size of the array: 9
Enter 9 elements of the array: 2 3 4 5 6 1 2 3 4
Sample Output:Distinct elements in the array are: 5 6 1