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:
- you never print number of matches
num
. instead of
return hand[i];
should either printhand[i]
or store in output container. should print contents of mentioned container (if use it) inmain()
in case
cout << printpairs(hand) << endl;
should changed appropriately decision taken in p.2
Comments
Post a Comment