The most occurring number in array(structure)

I cant find out whats wrong with this part of my program, i want to find out most occuring number in my structure(array), but it finds only the last number :/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void Daugiausiai(int n)
{
    int max = 0;
    int sk;
    for(int i = 0; i < n; i++){
            int kiek = 0;
        for(int j=0; j < n; j++){
            if(A[i].datamet == A[j].datamet){
                kiek++;
                if(kiek > max){
                    max = kiek;
                    sk = A[i].datamet;

                }

            }
        }
    }
}
Last edited on
This code is working fine for me. Are all your inputs correct?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
int main() //changed to main
{
	int A[10] = {400,300,100,100,200,100,700,100,800,400}; //added for an array
	int n=10; //correct size of array
    int max = 0;
    int sk;
    for(int i = 0; i < n; i++){
            int kiek = 0;
        for(int j=0; j < n; j++){
            if(A[i] == A[j]){ //changed to suit my array
                kiek++;
                if(kiek > max){
                    max = kiek;
                    sk = A[i];//changed to suit my array

                }

            }
        }
    }
	std::cout <<"max: " << max << std::endl;
	std::cout <<"sk: " << sk << std::endl;
}

output:

max: 4
sk: 100
Last edited on
Topic archived. No new replies allowed.