Maximum Value within a 1D Array
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This program defines an array and */
/* determines the maximum value with a function. */
#include <stdio.h>
HOMEWORK:
Assume that we have defined the following variables:
int k=6;
double data[]={1.5,3.2,-6.1,9.8,8.7,5.2};
Using the max function presented in this section, give the value of each of the following expressions:
- max(data,6);
- max(data,5);
- max(data,k-3);
- max(data,k%5);
1. This statement means that we must return the maximum value from the first six numbers in the data array. Therefore, the answer is 9.8.
2. This statement means that we must return the maximum value from the first five numbers in the data array. Therefore, the answer is 9.8.
3. Since k=6, we will look at the first k-3= 6 elements in the data array. Therefore, the maximum value is 3.2.
4. Since k%5= 1, we will only look at the first element in the data array. Therefore, the maximum value is 1.5.
No comments:
Post a Comment