본문 바로가기
C

3개의 정수 중 가장 작은 수 고르기 (if-else)

by KWONE 2024. 2. 2.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
int x, y, z;
int smallest;
printf("정수 3개를 입력하시오: ");
scanf("%d %d %d", &x, &y, &z);

if (x >= y) {
smallest = y;
if (z >= y)
smallest = y;
else
smallest = z;
}
else {
smallest = x;
if (z >= x)
smallest = x;
else
smallest = z;
}

printf("제일 작은 정수는 %d입니다.", smallest);
return 0;
}