~cpp #include <iostream> using namespace std; const int MAX_NUMBER=3; const int BREAK_NUMBER=-999; void change(int *number1, int *number2) { int temp=*number1; *number1=*number2; *number2=temp; } int input(int *input_number) { for (int i=0; i<MAX_NUMBER; ++i) { cout << i+1 << "번째 숫자를 입력해 주세요."; cin >> input_number[i]; if (0==i && input_number[0]==BREAK_NUMBER) return 0; } return 1; } void main() { int input_number[MAX_NUMBER]={0,}; while (input(input_number)) { for (int i=0; i<MAX_NUMBER-1; ++i) { for (int j=0; j<MAX_NUMBER-i-1; ++j) { if (input_number[j]>input_number[j+1]) change(&input_number[j],&input_number[j+1]); } } cout << "가운데 값은 " << input_number[MAX_NUMBER/2] << "입니다.\n"; } }
-module(pr_5). -export([getMiddle/3]). getMiddle(NumA, NumB, NumC) -> [_, A, _] = lists:sort([NumA, NumB, NumC]), A.
17> c(pr_5). {ok,pr_5} 18> pr_5:getMiddle(2, 5, 3). 3