the descent
problem sayfasi
// the descent
// yasin tasan - may 2018
#include <stdlib.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
unsigned int find_max();
unsigned int find_max_loc();
unsigned int arr[8] = {0};
unsigned int max = 0;
unsigned int loc = 0;
int main()
{
// game loop
while (1)
{
for (int i = 0; i < 8; i++)
{
int mountainH; // represents the height of one mountain.
scanf("%d", &mountainH);
arr[i] = mountainH;
}
max = find_max();
fprintf(stderr, "max = %d\n",max);
loc = find_max_loc();
fprintf(stderr, "loc = %d\n",loc);
printf("%d\n",loc);
max = 0;
}
return 0;
}
unsigned int find_max()
{
for(unsigned int i = 0; i<8; i++)
{
if(arr[i] > max)
{
max = arr[i];
}
}
return max;
}
unsigned int find_max_loc()
{
int i = 0;
for ( i= 0; i<8; ++i)
{
if (arr[i] == max)
{
return i;
}
}
}