Write a C++ Program That Show Distinct Number?

Write a C++ Program That Show Distinct Number
Means I Take 10 number from user and it eliminate repeated number and show non-repeated number only!
Cool, does it work?
All you have to do is put the numbers in a set:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <set>
#include <iostream>

int main()
{
    std::set<int> s;
    int n;
    while(cin >> n)
        s.insert(n);
    for(std::set<int>::const_iterator it = s.begin(); s != s.end(); ++s)
        std::cout << *s << std::endl;
    return 0;
}
Last edited on
I want it without using set

Using Loop and conditions!
any one have idea how to make C++ Program That Show Distinct Number
The traditional way would be for every user input, I would check an array if the number already exist or not. If exist, I don't put into the array else I put into the array.

Then after 10 numbers, I just output the array of numbers which is confirmed non-repeated.
$ cat - | sort | uniq
Topic archived. No new replies allowed.