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[100],i,j,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[j]==a[i])
{
printf("%d ",a[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