Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (anonymous):

program to read a sequence of N integers and print the number that appears the maximum number of times in the sequence.

OpenStudy (mandre):

Language? How far did you get?

OpenStudy (anonymous):

well, I dont know which language u are using so i will just give u a bit of the logic so you can think on it: say u store your sequence in an array. The only way to know the number that is occuring maximum numner of times is to compare it with other numbers. So you use a variable ,let the name of the variable be frequency,to keep a tab of the number of times a particualar number occurs in an array. Each time when you see the number again the valu of frequency inreases. Finally when you have compared a number with other number. store the value of frequency in another variable called max frequency (do this ony if the value of frequency greater than value max frequency). Now after getting out of the loop the value of max frequency will store the number of times the most frequent number has occured. Run another loop this time compare the value of frequenct with max frequency. Whn the match print the number for which they match.

OpenStudy (mandre):

That's all fine and well, but my language doesn't matter. Yours does. I use C++ (still learning), but you might be using Java or Python, which I don't know yet. I could write that in C++, but like I said, that won't help you if you're not using C++

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!