c++ - How can I make a function that prints out all repeated integers in an array? -


i have been trying make function prints out integers represented multiple times in array. following made print out first repeated integer(5), can't seem edit recognize second pair(6).

#include <iostream> #include <ctime> #include <cstdlib> using namespace std;  const int size = 5; struct pair{int one,two;}; pair get(int hand[]);  int main() {     int hand[size] = {5,6,5,2,6}; // input     pair number = get(hand);     cout << "pairs: " << number.one << ' ' << number.two << endl;      // should output: pairs: 5 6     return 0; }  pair get(int hand[]) {     int = 0, b = 0;     (int i=0;i<size;i++)     {          (int j=0;j<size;j++)         {             if (hand[i] == hand[j])             {                 = hand[i];             }         }     }     pair temp = {a,b};     return temp; } 

your code has 3 issues:

  1. you never print number of matches num.
  2. instead of return hand[i]; should either print hand[i] or store in output container. should print contents of mentioned container (if use it) in main()

  3. in case cout << printpairs(hand) << endl; should changed appropriately decision taken in p.2


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -