-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex10_04.c
49 lines (41 loc) · 1.05 KB
/
ex10_04.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* pr_pset10_04:
*
* Write a function that returns the index of the largest value stored in
* an array-of-double. Test the function in a simple program.
*/
#include <stdio.h>
#define SIZE 7
int l_index(double ar[], int size);
int main(void)
{
double num[SIZE] = {5.6,45.17,3.09,9.44,13.09,88.36,83.14};
printf("> Test of a function that returns the index\n"
"> of largest value stored in an array-of-double.\n");
printf("Indexes of array: ");
for (int i = 0; i < SIZE; i++)
printf(" [%d]", i);
printf("\nValues of an array-of-double:");
for (int i = 0; i < SIZE; i++)
{
printf("%6g", num[i]);
if ((i + 1) != SIZE)
printf(";");
}
printf("\nValue of [%d] element is the largest.\n", l_index(num,SIZE));
return 0;
}
int l_index(double ar[], int size)
{
int index;
double largest = 0.0L;
for (int i = 0; i < size; i++)
{
if (ar[i] > largest)
{
largest = ar[i];
index = i;
}
}
return index;
}