Advertisement
Evirir

Untitled

Nov 2nd, 2019
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int arr[20];            //the array of numbers
  7.     bool isInArray[101];    //an array that stores whether a number already exists in the array
  8.     int ptr=0;              //the current index in array
  9.    
  10.     //initialize all elements in isInArray[] to false
  11.     for(int i=0;i<101;i++){
  12.         isInArray[i]=false;
  13.     }
  14.    
  15.     cout<<"Please input 20 integers between 10 and 100, inclusive:\n"; //prompts the user to enter 20 integers
  16.    
  17.     for(int i=0;i<20;i++){
  18.         int temp;   //creates a variable to store the next number in input
  19.         cin>>temp;  //reads the input
  20.        
  21.         //checks whether the number already exists in the array, and stores the number if it does not
  22.         if(!isInArray[temp]){
  23.             arr[ptr]=temp;
  24.             ptr++;              //increments current index number
  25.         }
  26.        
  27.         isInArray[temp]=true;   //sets that the current number exists in the array
  28.     }
  29.    
  30.     cout<<"\nThe uniques values that you have entered:\n";
  31.    
  32.     for(int i=0;i<ptr;i++){
  33.         cout<<arr[i]<<" ";
  34.     }
  35. }
  36.  
  37. /*
  38. Please input 20 integers between 10 and 100, inclusive:
  39. 12 59 12 42 53 15 42 42 10 21 54 54 21 10 11 12 99 94 49 99
  40.  
  41. The uniques values that you have entered:
  42. 12 59 42 53 15 10 21 54 11 99 94 49
  43. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement