For C++ : find the largest repeating number in a vector.
Check : {3 , 4, 16, 2, 3, 16, 98, 4, 2,}
#include <iostream> #include <vector> using namespace std; int main() { vector<int> vec = {3, 4, 16, 2, 3, 16, 98, 4, 2}; int largest_repeating = 0, found = false; for (int i = 0; i < vec.size(); ++i) { for (int j = i+1; j < vec.size(); ++j) { if (vec[i] == vec[j]) { if (!found || vec[i] > largest_repeating) { largest_repeating = vec[i]; found = true; } } } } if (found) { cout << largest_repeating << endl; } else { cout << "Numbers are not repeating" << endl; } return 0; }
Get Answers For Free
Most questions answered within 1 hours.