DUPLICATE DETECTION
Problem Description
Jim was looking after a Given array which is already sorted. She found that it has duplicate elements. Your task is to help joyce by writing a program to display the duplicate element(s) present in the array.
CODING ARENA
#include <stdio.h>
int main()
{
int a,i,j;
scanf("%d",&a);
int arr[a];
for(i=0;i<a;i++)
scanf("%d",&arr[i]);
for(i=0;i<a;i++)
{
for(j=i+1;j<a;j++)
{
if(arr[i]==arr[j])
printf("%d ",arr[i]);
}
}
return 0;
}
Test Case 1
Input (stdin)5
5 4 2 2 5
Expected Output
5 2
Test Case 2
Input (stdin)4
55 66 99 99
Expected Output
99
No comments:
Post a Comment