Question: Write a function to find the largest number and the second largest number from an array. Since a function cannot return multiple values, we need

Write a function to find the largest number and the second largest number from an array. Since a
function cannot return multiple values, we need to use pointers to implement the function as follows:
void find_two_largest(int a[], int n, int *largest, int *second_largest);
When passed an array a of length n, the function will search a for its largest and second-largest
elements, storing them in the variables pointed to by largest and second_largest respectively.
In addition to find_two_largest function, you are expected to implement main function. main function
will (1) ask for user inputs; (2) call find_two_largest; (3) print the result as the example output below.
The input is the array size followed by the elements in the array. Please name the program as
findLargests.c.
Example input:
46789
Example output:
Largest number: 9
Second largest number: 8

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 Programming Questions!