CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 16

Threaded View

  1. #9
    Join Date
    Oct 2009
    Posts
    7

    Re: Array Duplicates

    Got it working, thanks for your help.

    Here is my code
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    int num[10];
    bool is_dup;
    cout << "Enter 10 numbers..." <<endl;
    for (int i=0; i<10; i++)
    {
            cin >> num[i];
    }
    
    for (int j=0; j<10;j++)
    {
            is_dup= false;
            for (int k=j+1; k<10; k++) //this will repeat from j-1 to 0
            {
                    if (num[j] == num[k]) //checks if one number is equal to others below it
                    is_dup = true; //You found a duplicate
            }
    
            if (is_dup == false)
            cout << num[j] << " ";
    
    }
    cout << endl;
    
    
    return 0;
    }
    edit: woops didnt really change some of my comments...
    Last edited by viperlasson; October 21st, 2009 at 12:57 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured