홀짝 구분하기

SmartBear·2025년 12월 12일

CodingTest

목록 보기
11/30

프로그래머스

홀짝 구분하기

문제 링크

문제

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

  • 제한사항
    • 1 ≤ n ≤ 1,000
  • 입출력 예
    • 입력 #1
      100
    • 출력 #1
      100 is even
    • 입력 #1
      1
    • 출력 #1
      1 is odd

코드

using System;

public class Example
{
    public static void Main()
    {
        String[] s;

        Console.Clear();
        s = Console.ReadLine().Split(' ');

        int a = Int32.Parse(s[0]);
        if (a % 2 == 1) Console.WriteLine($"{a} is odd");
        else Console.WriteLine($"{a} is even");
    }
}

정답률

정확성: 100.0
합계: 100.0 / 100.0
profile
Python Dev with Infra -> Game Programmer

0개의 댓글