-
Functions코딩 테스트/HackerRank 2021. 9. 15. 21:57
https://www.hackerrank.com/challenges/c-tutorial-functions/problem
Functions | HackerRank
Learn how to write functions in C++. Create a function to find the maximum of the four numbers.
www.hackerrank.com
#include <iostream> #include <cstdio> using namespace std; /* Add `int max_of_four(int a, int b, int c, int d)` here. */ int max_of_four(int a, int b, int c, int d) { int temp1, temp2; if (a > b) temp1 = a; else temp1 = b; if (c > d) temp2 = c; else temp2 = d; return temp1 > temp2 ? temp1 : temp2; } int main() { int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); int ans = max_of_four(a, b, c, d); printf("%d", ans); return 0; }
'코딩 테스트 > HackerRank' 카테고리의 다른 글
For Loop (0) 2021.09.16 Pointer (0) 2021.09.14 Print the Elements of a Linked List (0) 2021.09.13