Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int arr[20]; //the array of numbers
- bool isInArray[101]; //an array that stores whether a number already exists in the array
- int ptr=0; //the current index in array
- //initialize all elements in isInArray[] to false
- for(int i=0;i<101;i++){
- isInArray[i]=false;
- }
- cout<<"Please input 20 integers between 10 and 100, inclusive:\n"; //prompts the user to enter 20 integers
- for(int i=0;i<20;i++){
- int temp; //creates a variable to store the next number in input
- cin>>temp; //reads the input
- //checks whether the number already exists in the array, and stores the number if it does not
- if(!isInArray[temp]){
- arr[ptr]=temp;
- ptr++; //increments current index number
- }
- isInArray[temp]=true; //sets that the current number exists in the array
- }
- cout<<"\nThe uniques values that you have entered:\n";
- for(int i=0;i<ptr;i++){
- cout<<arr[i]<<" ";
- }
- }
- /*
- Please input 20 integers between 10 and 100, inclusive:
- 12 59 12 42 53 15 42 42 10 21 54 54 21 10 11 12 99 94 49 99
- The uniques values that you have entered:
- 12 59 42 53 15 10 21 54 11 99 94 49
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement