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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started