Program hotrotinhoc;
var x,i,max,n: integer;
a,b: array[1..20] of integer;
begin
write('N='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
inc(b[a[i]]);
end;
max:=0;
for i:=1 to n do
if b[a[i]]>max then
begin
max:=b[a[i]];
x:=a[i];
end;
write('Phan tu co so lan xuat hien nhieu nhat trong mang la :',x);
readln
end.
#include <iostream> #include <algorithm> using namespace std; int main() { int a[] = { 5,5,5,5,5,4,4,4,4,3,3,3,2,2,1 }; int n = sizeof(a)/sizeof(a[0]); sort(a,a+n); int i = 0, max = 0,index = 0; int frequency; while(i < n) { frequency = 1; while(a[i] == a[i+1]) { frequency++; i++; } if(max < frequency) { max = frequency; index = i; } i++; } cout << "Maximum frequency: " << max << endl; cout << "Element has maximum frequency factor: " << a[index] << endl; return 0; }