finds and displays the kth largest value in an array that is less than some threshold value
Modify the selection.c program (available on the Moodle site) so that it finds and displays the kth largest value in an array that is less than some threshold value. The threshold and k are specified by the user. N numbers are read from the file floats.txt which you can download from the csmoodle site and N is specified by the user.
The preloaded template contains the code to read the values from the user and file. Do not change this code. Make sure to put floats.txt into your C programs folder, so that the program will be able to open it and read in the array values.
When the kth largest value is found, for example for k=5, threshold=0.8 and N=10, the program should print out
The k=5 largest value in the array that is less than 0.80000 is 0.45865
Floating point numbers should be printed to 5 decimal places.
When there are not k numbers in the array that are less than the threshold, the program should print out
The array does not contain 5 numbers less than 0.80000
________________________________________________________
This is the code I was given
________________________________________________________
#include <stdio.h>
#include <stdbool.h>
#define MAX_SIZE 5000
int main(void)
{
int i, k, N;
double a[MAX_SIZE];
double threshold;
FILE *fp;
printf("Enter number of values to read from floats.txt\n");
scanf("%d", &N);
printf("Enter the threshold value\n");
scanf("%lf", &threshold);
printf("Enter the value of k\n");
scanf("%d", &k);
fp = fopen("floats.txt", "r");
for (i = 0;i<N;i++)
{
fscanf(fp, "%lf", &a[i]);
}
fclose(fp);
/* write your solution here */
return 0;
}
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)