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 using namespace std;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!