PEASE MAKE SURE TO DO SAMPLE RUNS TO MAKE SURE THE PROGRAM WORKS BEFORE SUBMITTI
ID: 3532395 • Letter: P
Question
PEASE MAKE SURE TO DO SAMPLE RUNS TO MAKE SURE THE PROGRAM WORKS BEFORE SUBMITTING YOUR ANSWER!!!!
Minimum Value in an array. Write an int function min_dbl_arr() that will find the minimum value of a one-dimensional array of doubles. The function should return the index of the array element that has the minimum value(using the return statement) and pass the minimum value back through the parameter list. Modify the main() function from Listing 9-2 so that it calls min_dbl_arr() and prints the minimum value and its index on the standard output.
Listing 9-2
#include<stdio.h>
#define SIZE 100
int get_dbl_arr(double array[ ]);
void print_dbl_arr(double array[ ], int n);
double ave_dbl_arr(double array[ ], int n);
void copy_dbl_arr(double array1[ ], double array2[ ], int n);
void sort_dbl_arr(double array[ ], int n);
main()
{
double list[SIZE], sorted_list[SIZE];
double ave_value;
int n;
n = get_dbl_arr(list);
printf("%d values read: ", n);
print_dbl_arr(list, n);
ave_value = ave_dbl_arr(list, n);
printf(" The average is %g ", ave_value);
copy_dbl_arr(list, sorted_list, n);
sort_dbl_arr(sorted_list, n);
printf(" The sorted array: ");
printf_dbl_arr(sorted_list, n);
Explanation / Answer
#include<stdio.h>
#define SIZE 100
int get_dbl_arr(double array[ ]);
void print_dbl_arr(double array[ ], int n);
double ave_dbl_arr(double array[ ], int n);
void copy_dbl_arr(double array1[ ], double array2[ ], int n);
void sort_dbl_arr(double array[ ], int n);
double min_dbl_arr(double arraymin[], int n)
{
double i,Min=0,R;
Min=arraymin[0];
R=0;
for ( i=1; i<n ; i++)
{
if( arraymin[i]<Min)
{
Min=arraymin[i];
R=i;
}
return R;
}
main()
{
double list[SIZE], sorted_list[SIZE],Mini;
double ave_value;
int n;
n = get_dbl_arr(list);
printf("%d values read: ", n);
print_dbl_arr(list, n);
ave_value = ave_dbl_arr(list, n);
printf(" The average is %g ", ave_value);
copy_dbl_arr(list, sorted_list, n);
sort_dbl_arr(sorted_list, n);
printf(" The sorted array: ");
printf_dbl_arr(sorted_list, n);
Mini= min_dbl_arr( list , n);
printf("Minimum is %d ", list[Mini];
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.