#include <stdio.h>
int main() {
int a[10];
for (int i = 0; i < 10; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < 10; i++) {
for (int j = i + 1; j < 10; j++) {
if (a[i] == a[j]) {
printf("%d ", a[i]);
for(int n=0;n<10;n++){
if(a[n]==a[i]){
a[n]=-1;
}
}
//printf("%d ", a[i]);
break;
}
}
}
return 0;
}
This code reads 10 integers into an array, then prints each value that appears more than once. It marks duplicates by setting them to -1 to avoid printing the same number multiple times.
- The inner loop that sets elements to -1 runs from index 0 to 9 each time a duplicate is found. This can cause the outer loop to later compare against elements that were already changed to -1, which might affect the logic for detecting other duplicates.
- The break statement only exits the inner loop after finding the first duplicate, but the marking loop then continues to modify the array. Consider whether the break should happen before or after the marking, and whether the marking loop needs to run for all indices or only for certain ones.