Question: Write a C program that finds the largest and second largest elements in an array. Use the random number generator rand() to initialize the array

Write a C program that finds the largest and second largest elements in an array. Use the random number generator rand() to initialize the array with 20 numbers with values in the range of 1 to 50. Create a function for finding the maximum and second maximum values in the array by passing the array into the function and also using pointers as function arguments.

The prototype of the function should be:

void max1_max2 (int a[], int n, int *max1, int *max2);

/* *max1 points to the maximum value, and *max2 points to the second maximum. */

A call of max1_max2 might have the following appearance:

max1_max2 (b, N, &big1, &big2);

An example run of the program is as follows,

20 random numbers in the range of 1 to 50:

1 50 23 16 29 28 50 20 19 17 19 38 37 21 17 43 35 25 31 10

The largest value is: 50

The second largest value is: 43

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!