Question

(Print distinct numbers) C++ Write a program that reads in 10 numbers and displays distinct numbers...

(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 <iostream>
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;

}


}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
using namespace std;

void read(int array1[], int number) {
    //read numbers
    cout << "Enter ten numbers: ";
    for (int i = 0; i < number; i++) {
        cin >> array1[i];
    }
}

void display(int array1[], int numbers) {
    bool found;
    cout << "The distinct numbers are: ";
    for (int i = 0; i < numbers; i++) {//if first spot
        found = false;
        for (int j = 0; j < i; ++j) {
            if (array1[i] == array1[j]) {
                found = true;
            }
        }
        if(!found) {
            cout << array1[i] << " ";
        }
    }
    cout << endl;
}

int main() {//declarations
    int array1[10];
    int number = 10;

    read(array1, number);
    display(array1, number);

    return 0;
}

Add a comment
Know the answer?
Add Answer to:
(Print distinct numbers) C++ Write a program that reads in 10 numbers and displays distinct numbers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • java for netbeans Question 2: (Print distinct numbers) Write a program that reads in ten numbers...

    java for netbeans Question 2: (Print distinct numbers) Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it. After the input, the array contains the distinct numbers. Here is the...

  • Java Programming. Write your own source code with comments. (Print distinct numbers) Write a program that...

    Java Programming. Write your own source code with comments. (Print distinct numbers) Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct...

  • (Count positive and negative numbers and compute the average of numbers) Write a program that reads...

    (Count positive and negative numbers and compute the average of numbers) Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number. If you entire input is 0, display 'No numbers are entered except 0.' *So I think my code is looping because the...

  • Lab 10A Measure the program execution time One easy way to measure the program execution time is ...

    Lab 10A Measure the program execution time One easy way to measure the program execution time is encapsulate the useful timing functionality of C++ chrono library, This is illustrated inhttps://www.learncpp.com/cpp-tutorial/8-16-timing-your-code/ The example usingChronoTimer.cpp (Github/m10) is an example program using this chrono Timer class object to measure the Sorting on on an integer array of 10000 random integers based on the Bubble Sort vs. the C++ built-in Sort (an https://www.quora.com/Which-sorting-algorithm-does-STL-standard-template-library-use-in-c++. ) Please measure the performance of sorting the same array used...

  • read in numbers into array , print out, sort - my program reads in and prints...

    read in numbers into array , print out, sort - my program reads in and prints out but crashes before the sort - crashes after it prints out the scores - *important I have to use pointers!!!! c++ #include <iostream> using namespace std; void sortarray(int *tarray, int ); void displayarray(int *[], int); void averageshowarray(int *[], int); int main() {     int Size;     int count;     cout << "enter the size: " << endl;     cin >> Size;     int...

  • Write a C++ program that simulates playing the Powerball game. The program will generate random numbers...

    Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...

  • Display all the distinct numbers and their frequencies in the array. Hint: Use a map. STARTER...

    Display all the distinct numbers and their frequencies in the array. Hint: Use a map. STARTER CODE: import java.util.HashMap; public class NumberFrequncies {    public static void main(String[] args) {        int[] numbers = {2, 3, 0, 1, -1, 9, 10, 10, 9, 3, 0, 2};               //TODO: ------------        /* Add code below to store the distinct numbers and their count        * in a data structure called numberFrequencyMap        */   ...

  • Remove srand(time(NULL)); from this C++ code so that it still finds random numbers correctly. Then, Write...

    Remove srand(time(NULL)); from this C++ code so that it still finds random numbers correctly. Then, Write a program that adds the following to the fixed code. • Add a function that will use the BubbleSort method to put the numbers in ascending order. – Send the function the array. – Send the function the size of the array. – The sorted array will be sent back through the parameter list, so the data type of the function will be void....

  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

  • Write a program that prompts the user to enter the number of milliseconds and converts the milliseconds to a string hours:minutes:seconds

    Problem 1.Write a program that prompts the user to enter the number of milliseconds and converts the milliseconds to a string hours:minutes:seconds. The program should use the convertMillismethod with the following header:public static String convertMillis(long millis)For example, convertMillis(5500) returns the string 0:0:5, convertMillis(100000) returns the string 0:1:40, andconvertMillis(555550000) returns the string154:19:10.Problem 2. (Count occurrence of numbers)Write a program that reads integers between 1 and 100 and counts the occurrence of each (you should store the numbers in an array). Output...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT