How do i find a minimum across multiple array's of data

So i got a question where i need to display the year where the minimum is found and its number. i got the result to post but it loops. how do i set it up so it only displays the year and the data from the array it represents?

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
 float LAN(void)
{
	int min;

	min = Y2012[1];
	printf("The Minimum is %d\n and the minimum year is 2012\n", min);
	if (Y2013[1] < min)
	{
		min = Y2013[1];
		printf("The Minimum is %d\n and the minimum year is 2013\n", min);
	}
	if (Y2014[1] < min)
	{
		min = Y2014[1];
		printf("The Minimum is %d\n and the minimum year is 2014\n", min);
	}
	if (Y2015[1] < min)
	{
		min = Y2015[1];
		printf("The Minimum is %d\n and the minimum year is 2015\n", min);
	}
	if (Y2016[1] < min)
	{
		min = Y2016[1];
		printf("The Minimum is %d\n and the minimum year is 2016\n", min);
	}
}
I see no "loop" in your code. Not much or arrays either, but lets ignore that.
1
2
3
4
5
6
int min;
int year;

// set those values

printf("The Minimum is %d\n and the minimum year is %d\n", min, year );

In other words, you cannot print anything before you do know the result. In your code you don't know it until after line 26. Since you can store the "least value found so far", you can surely store "year of that least value so far".
I see... so i should put

If(Y2013[1]<min)

min=2013[1];
year=2013


printf("The minimum is %d and the year of it is %d\n",min,year)
Registered users can post here. Sign in or register to post.