Sir please help me to solve this question.
How to find a no repeated maximum times in an 1D array.
eg an array is 1,2,4,4,8,4,3,7,4,9,4
output should be 4
1
Expert's answer
2012-10-02T11:19:04-0400
#include <stdio.h>
#include <conio.h>
#define MAX 50
main(){
int array[MAX], n, i, j, tmp, repeat;
printf("Number of elements array = "); scanf("%i",&n);
printf("Type array elements: ");
for(i=0; i<n; i++){
printf("Array[%i] = ",i); scanf("%i",&array[i]);
if(array[i]==0) break;
}
for(i=0; i<n; i++){
tmp = 0;
for(j=(i+1); j<n; j++){
if(array[i] < array[j]){
tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
}
}
printf("The result of sorting: ");
for(i=0; i<n; i++){
printf("%i ",array[i]);
}
printf(" Repeated elements: ");
for(i=0,tmp=0; i<n; i++){
for(j=(i+1); j<n; j++){
if(array[i] == array[j]){
tmp++;
printf("%i %i ",array[i],array[j]);
}
}
}
if(tmp > 0){
printf(" The number of repetitions: %i",tmp);
} else printf(" The array elements is not repeated");
Comments
Leave a comment