How to find Duplicate elements in an array in C
#include<stdio.h> int main () { int n , i , j , flag = 0 , arr [ 20 ]; printf ( "Enter size of array : \n" ); scanf ( "%d" ,& n ); printf ( "array element are =\n" ); for (i = 0;i<n;i++) { printf("\n arr[%d]= ",i); scanf("%d",&arr[i]); } for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(arr[i]==arr[j]&&i!=j) { flag=1; printf("Duplicate number position are %d and %d",i,j); } } } if(flag==0) printf("no duplicate"); } Output: Enter size of array : 5 array element are = arr[0]= 2 arr[1]= 3 arr[2]= 4 arr[3]= 3 arr[4]= 6 Duplicate number position are 1 and 3