| | |
Finding the mode value and its frequency!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Well, do you understand what the frequency and mode are? The mode can be easily found once you've obtained the frequency, and the frequency is trivial with the standard library:
Now it's just a matter of finding the item with the largest value for second.
C++ Syntax (Toggle Plain Text)
#include <cstddef> #include <iostream> #include <map> #define length(x) (sizeof (x) / sizeof *(x)) int main() { int a[] = {1,5,4,5,8,9,5,1,4,7,8,5}; std::map<int, int> freq; for ( size_t i = 0; i < length ( a ); i++ ) ++freq[a[i]]; std::map<int, int>::const_iterator it = freq.begin(); while ( it != freq.end() ) { std::cout<< it->first <<": "<< it->second <<std::endl; ++it; } }
I'm here to prove you wrong.
•
•
Join Date: Apr 2005
Posts: 4
Reputation:
Solved Threads: 0
thanks to give me an idea. I found out the different way to find the frequency. this is what I did :
<< moderator edit: added [code][/code] tags >>
well, I found the most frequency and then I found mode!
C++ Syntax (Toggle Plain Text)
int j(1); mode[j] = slist[1]; freq[j]= 1; for (int i=2;i<=n;i++) { if (mode[j] == slist[i]) freq[j]++; else { j++; mode [j] = slist [i]; freq[j]= 1; }//end if }//end for
well, I found the most frequency and then I found mode!
![]() |
Similar Threads
- I can't boot into safe mode? (Troubleshooting Dead Machines)
- help please (C++)
- Firefox 'crashing' in normal mode (Web Browsers)
- g3 display "out of frequency range" (Apple Hardware)
- mode prog in c (C)
Other Threads in the C++ Forum
- Previous Thread: AHHHH!! i cant figure this out.
- Next Thread: Selectoin SOrt
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






