본문 바로가기
알고리즘

[C] 백준 2562

by mokhwasomssi 2021. 3. 10.

for문을 이용해 최대값을 갱신하면서 최종 최대값을 찾는 문제

주어진 수가 9개 이므로 숫자 두 개씩 비교하는 크기비교는 8번 수행

 

#include <stdio.h>

int main()
{

	int num[9];
	int max = 0;

	for (int i = 0; i < 9; i++)
		scanf("%d", &num[i]);

	for (int i = 1; i < 9; i++)
	{
		if (num[i] > num[max])
			max = i;
	}

	printf("%d \n%d", num[max], max + 1);

	return 0;
}