프로그래머스 - 181944

노력하는백엔드·2025년 12월 19일

알고리즘

목록 보기
5/31

홀짝 구분하기

문제 설명

자연수 n이 입력으로 주어졌을 때 만약 n이 짝수이면 "n is even"을, 홀수이면 "n is odd"를 출력하는 코드를 작성해 보세요.

제한 사항

  • 1 ≤ n ≤ 1,000

입출력 예

제출 코드

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];

rl.on('line', function (line) {
    input = line.split(' ');
}).on('close', function () {
    n = Number(input[0]);
    if(n % 2 == 0){
        console.log(`${n} is even`)
    }else{
        console.log(`${n} is odd`)
    }
});
profile
열심히 노력하는 백엔드입니다.

0개의 댓글