-
October 19th, 2009, 11:23 PM
#1
Array Duplicates
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...
Code:
#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];
And that's where I'm at. We are also not allowed to sort the array. I wanted to try something like
Code:
int n=0;
for(int j=0; j<10;j++)
{
if(num[n] != num[n+1]
cout << num[i]
n++;
}
but since it isn't sorted, it will not check any previous numbers in the array, only the one next to it...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|