0
Find the duplicate element
Assuming an array of 100 elements with values between 1-99,one of the elements is duplicate.write a program to find the duplicate element
5 Respostas
+ 1
#include <stdio.h>
void main()
{
int i,n=0;
int arr[100];
int j = 0;
int prev = 0;
printf("Enter total no. of the elements : ");
scanf("%d",&n);
printf("Enter total %d elements : \n",n);
for(i=0; i<n; i++)
scanf("%d",&arr[i]);
for(i=0; i<n-1; i++) {
j++;
if( j < n){
i = prev;
}
else{
j = i + 1;
}
if(arr[i] < arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
prev = i;
}
printf("\nSorted Array : ");
for (i = 0; i < n; i++) {
printf(" %d,",arr[i]);
}
printf("\nDuplicate :");
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n ; j++) {
if (arr[i] == arr[j]) {
printf(" %d,",arr[i]);
}
}
}
}
0
thanks bro
0
Is it Useful to you..??
0
it's not showing the.
duplicate value..
and i have no need of shorted array..
0
now its work fine...
thanks