Question

For C++ : find the largest repeating number in a vector. Check : {3 , 4,...

For C++ : find the largest repeating number in a vector.

Check : {3 , 4, 16, 2, 3, 16, 98, 4, 2,}

Homework Answers

Answer #1
#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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider the vector field ?(?,?,?)=(3?+3?)?+(4?+3?)?+(4?+3?)?. a) Find a function ? such that ?=∇? and ?(0,0,0)=0. ?(?,?,?)=  ...
Consider the vector field ?(?,?,?)=(3?+3?)?+(4?+3?)?+(4?+3?)?. a) Find a function ? such that ?=∇? and ?(0,0,0)=0. ?(?,?,?)=   b) Suppose C is any curve from (0,0,0) to (1,1,1). Use part a) to compute the line integral ∫C ?⋅??
find all scalars c if any exists such that the vector [-3, 3] is a linear...
find all scalars c if any exists such that the vector [-3, 3] is a linear combination of the vector [-3,5] and [6,c]]
1a. Find a vector equation for the line segment from (4, −3, 7) to (8, 3,...
1a. Find a vector equation for the line segment from (4, −3, 7) to (8, 3, 4).  (Use the parameter t.) 1b. Find an equation of the plane. The plane through the point (7, 4, 9) and with normal vector 2i + j − k 1c.  Find an equation of the plane. The plane through the point (2, −5, −9) and parallel to the plane 6x − y − z = 4
A) Find a vector that measures 3 in the direction of the vector 2i + 3j...
A) Find a vector that measures 3 in the direction of the vector 2i + 3j - k B) Given the vectors a = 2i + 3j - k and b = -2i + 3j + k. Find 2a 3 b and |a-b| C) Find the vector that goes from point P (2, -1,4) to point Q (3, -2,6)
using a C++ code find the largest number from two numbers. also considering the case that...
using a C++ code find the largest number from two numbers. also considering the case that the two numbers are equal.
With numbers 2, 3, 4, 5, 7 and 9 three-digit numbers are made without repeating, that...
With numbers 2, 3, 4, 5, 7 and 9 three-digit numbers are made without repeating, that is, no 334-type numbers are allowed. How many different numbers can be formed if a) There are no restrictions b) Let them be even numbers c) They are odd numbers step by step please
A (–4, –1, 2), B (3, –2, –1) and C (–1, 3, –4), AB= 7? −...
A (–4, –1, 2), B (3, –2, –1) and C (–1, 3, –4), AB= 7? − ? − 3? CB = 4? − 5? + 3? AC = 3? + 5? - 2? Question 7: Express the vector AC as the sum of two vectors: AC = ? + ?, where ? is parallel to the vector CB and ? is perpendicular to CB. Given that AC ∙ CB = −26 and that CB = √50, determine the y-component of...
let us create a variable for a row vector a = [1, 4, 1, 3, 2,...
let us create a variable for a row vector a = [1, 4, 1, 3, 2, 5, 0] and calculate the mean value of its elements using the Matlab function ‘mean’ and store this value in variable aMean. Fig. 1 gives the Matlab code to do this. a = [1, 4, 1, 3, 2, 5, 0]; aMean = mean(a); Figure 1: Matlab code – row vector and mean of its elements. Let us now construct a row vector b that...
Given vector ? = 2? + 3?, ? = −5? + ? + ?. Find the...
Given vector ? = 2? + 3?, ? = −5? + ? + ?. Find the followings. a) The projection of u onto v b) A vector that is orthogonal to both u and v
Find (a) a vector-valued function, (b) parametric equations, and (c) a Cartesian equation for the line...
Find (a) a vector-valued function, (b) parametric equations, and (c) a Cartesian equation for the line that is parallel to the vector <−2, 6> and passes through the point P(−4, 5)