Day2_홀짝 구분

Subin·2024년 6월 27일

Algorithm

목록 보기
3/69

[내 풀이]

#include <iostream>

using namespace std;

int main(void) {
    int n;
    cin >> n;

    if(n % 2 == 0)
        cout << n << " is even";
    else
        cout << n << " is odd";
    return 0;
}

[다른 사람 풀이]

#include <iostream>

using namespace std;

int main(void) {
    int n;
    cin >> n;
    cout << n << " is " << (n%2==0 ? "even":"odd");
    return 0;
}

삼항연산자를 잘 활용하자!

profile
성장하며 꿈꾸는 삶을 살아가고 있는 대학생입니다😊

0개의 댓글