# Answer to Question #15632 in C++ for Neeraj

Question #15632

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

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

Expert's answer

#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");

getch();

return 0;

}

#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");

getch();

return 0;

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment