A group of kids enjoys playing a numbers game where they must identify the distinct numbers in a sequence and sort them in ascending order. This program helps them verify their answers.
Table of Contents 📖
Write a C program that finds the distinct numbers in a sequence, sorts them in ascending order, and verifies the kids' answers. The program must use specific functions as described below.
- An integer
n
, the size of the sequence. - A sequence of
n
integers.
- The distinct numbers in ascending order, separated by spaces.
Enter numbers: 12 25 5 25 12 8 5 12
Output: 5 8 12 25
Enter numbers: 12 25 5 2 8
Output: 2 5 8 12 25
Enter numbers: 12 12 15 12 15
Output: 12 15
-
The program must include the following functions:
int find_distinct(int numbers[], int n, int result[]);
Finds the distinct numbers in the arraynumbers
, stores them inresult
, and returns the count of distinct numbers.-
A
selection_sort
function from the textbook to sort the numbers after finding the distinct elements.
- In the main function, call the above functions and display the result.
1. Compile the Program:
2. Run the Program:
3. Input Required:
- The size of the sequence
n
. - A sequence of
n
integers.