Please help with this C++ problem using Array Use a one-dimensional array to sol
ID: 3851734 • Letter: P
Question
Please help with this C++ problem using Array
Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100. As each number is read validate it and store it in the array. After reading all the values, display only the unique values that the user entered. Make sure you account for the worst case scenario in which all 20 numbers are different. Use the smallest possible array to solve this problem. Printing unique numbers: 10 11 12 13 14 15 16 17 18 19 20 22Explanation / Answer
C++ Program :
#include <iostream>
using namespace std;
int main() {
// using array as map. I store the input numbers in the given map
int map[101],n;
for(int i=0;i<=100;i++){
map[i] = 0;
}
for(int i=1;i<=20;i++){
cout<<"Input a number between 10 and 100 :";
cin>>n;
//Store the number in a map
map[n] = 1;
cout<<endl;
}
cout<<"printing unique numbers"<<endl;
for(int i=10;i<=100;i++){
//Output the number if the map is not equal to 0
if(map[i]!=0){
cout<<i<<endl;
}
}
return 0;
}
OUTPUT:
Success time: 0 memory: 16064 signal:0