Question
(Print distinct numbers) C++ Write a program that reads in 10 numbers and displays distinct numbers (i.e., if a number appears multiple times, it is
(Print distinct numbers) C++
Write a program that reads in 10 numbers and displays distinct numbers (i.e., if a number appears multiple times, it is displayed only once). The numbers are displayed in the order of their input and separated by exactly one space.
(Hint: Read a number and store it to an array if it is new. If the number is already in the array, discard it. After the input, the array contains the distinct numbers.)
Sample Run
Enter ten numbers: 1 2 3 2 1 6 3 4 5 2
The distinct numbers are: 1 2 3 6 4 5
Hey I'm not sure where to place my parameters with this program
This is what I got so far...
Thanks in advance!
#include
void read(int array1[], int number) { //read numbers cout << "Please enter ten numbers"; for (int i = 0; i < array1[i]; i++) { cin >> array1[i]; } } void display(int array1[], int array2[], int numbers){ for(int i=0,i) { for (int j = i + 1; j) {//store the number if new if ((array2[i] == 0 && (array[1]==array1[j]))) { array2[j] = 1;
} } cout << "The distinct number are: "; for (int i = 0; i) {//if first spot if (array2[i] == 0) { cout << array1; } } int main() {//declarations int array1[10]; int array2[10] = { 0 }; int number = 10;
cout << "Distinct number: "; read(array1, number); display(array1, array2, number); cout << endl; return 0;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started