Hi everyone, I'm new and will probably be asking a lot of questions from here on out. I have an assignment where the user inputs 10 integers into an array, then the program is supposed to output the numbers, but no duplicates. (ex. INPUT: 1 2 2 3 1 10 6 4 6 20 OUTPUT: 1 2 3 10 6 4 20)
What I'm having trouble with is figuring out the algorithm needed to not cout the duplicates.
Here's what I have...
And that's where I'm at. We are also not allowed to sort the array. I wanted to try something likeCode:#include <iostream> using namespace std; int main() { int num[10]; cout << "Enter 10 numbers...\n"; for(int i=0; i<10;i++) cin >> num[i];
but since it isn't sorted, it will not check any previous numbers in the array, only the one next to it...Code:int n=0; for(int j=0; j<10;j++) { if(num[n] != num[n+1] cout << num[i] n++; }


Reply With Quote
Bookmarks