Hello, Can someone please help me with the C++ code for finding 2frequent number
ID: 3618124 • Letter: H
Question
Hello,Can someone please help me with the C++ code for finding 2frequent numbers in an array?
here's what I have so far: I found this on a website, but it'sonly for finding the mode for 1 number.
Thanks!
#include <iostream> using namespace std;
const int n = 10;
int main() {
int a[n] = {1,2,2,2,2,3,3,3,3,5}; int x = 1;
int arr[n]; int j=0;
int currvalue = a[0]; // start from the 1st element int counter = 0; int maxcounter = 1; int modevalue = a[0]; for (int i = 1; i < n; ++i) { if (a[i] == currvalue) { ++counter; cout << "Counter: " << counter <<endl; cout << " Number: " << a[i] << endl; } else { // next value started... if (counter >maxcounter) { // new mode candidate maxcounter = counter; modevalue =currvalue; if(counter == maxcounter) {
arr[j] = currvalue; j++;
cout << "Number: " << arr[j] << endl; } }
currvalue = a[i]; // ready tocount next values counter = 1; }
} // Check last value, copy code...
for (j = 0; j < n; j++) { cout << "N:" << arr[j] << endl; }
return 0; }
Can someone please help me with the C++ code for finding 2frequent numbers in an array?
here's what I have so far: I found this on a website, but it'sonly for finding the mode for 1 number.
Thanks!
#include <iostream> using namespace std;
const int n = 10;
int main() {
int a[n] = {1,2,2,2,2,3,3,3,3,5}; int x = 1;
int arr[n]; int j=0;
int currvalue = a[0]; // start from the 1st element int counter = 0; int maxcounter = 1; int modevalue = a[0]; for (int i = 1; i < n; ++i) { if (a[i] == currvalue) { ++counter; cout << "Counter: " << counter <<endl; cout << " Number: " << a[i] << endl; } else { // next value started... if (counter >maxcounter) { // new mode candidate maxcounter = counter; modevalue =currvalue; if(counter == maxcounter) {
arr[j] = currvalue; j++;
cout << "Number: " << arr[j] << endl; } }
currvalue = a[i]; // ready tocount next values counter = 1; }
} // Check last value, copy code...
for (j = 0; j < n; j++) { cout << "N:" << arr[j] << endl; }
return 0; }
#include <iostream> using namespace std;
const int n = 10;
int main() {
int a[n] = {1,2,2,2,2,3,3,3,3,5}; int x = 1;
int arr[n]; int j=0;
int currvalue = a[0]; // start from the 1st element int counter = 0; int maxcounter = 1; int modevalue = a[0]; for (int i = 1; i < n; ++i) { if (a[i] == currvalue) { ++counter; cout << "Counter: " << counter <<endl; cout << " Number: " << a[i] << endl; } else { // next value started... if (counter >maxcounter) { // new mode candidate maxcounter = counter; modevalue =currvalue; if(counter == maxcounter) {
arr[j] = currvalue; j++;
cout << "Number: " << arr[j] << endl; } }
currvalue = a[i]; // ready tocount next values counter = 1; }
} // Check last value, copy code...
for (j = 0; j < n; j++) { cout << "N:" << arr[j] << endl; }
return 0; }
Explanation / Answer
please rate - thanks #include using namespace std; void sort(int[],int); void mode(int [],int ,int&,int[]); int main() {int x[200],i=0,j,kt=0,index[10]; double average,sd,variance; kt=0; coutx[kt]; while(ktRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.