2024. 8. 7. 09:35ㆍIT/BaekJoon
문제 링크
https://www.acmicpc.net/problem/10480
문제
Some numbers are just, well, odd. For example, the number 3 is odd, because it is not a multiple of two. Numbers that are a multiple of two are not odd, they are even. More precisely, if a number n can be expressed as n = 2 ∗ k for some integer k, then n is even. For example, 6 = 2 ∗ 3 is even.
Some people get confused about whether numbers are odd or even. To see a common example, do an internet search for the query “is zero even or odd?” (Don’t search for this now! You have a problem to solve!)
Write a program to help these confused people.
입력
Input begins with an integer 1 ≤ n ≤ 20 on a line by itself, indicating the number of test cases that follow. Each of the following n lines contain a test case consisting of a single integer −10 ≤ x ≤ 10.
출력
For each x, print either ‘x is odd’ or ‘x is even’ depending on whether x is odd or even.
통과한 답안
namespace _10480
{
internal class Program
{
static void Main(string[] args)
{
int N = int.Parse(Console.ReadLine());
for (int i = 0; i < N; i++)
{
int num = int.Parse(Console.ReadLine());
if (num % 2 == 0)
{
Console.WriteLine($"{num} is even");
}
else
{
Console.WriteLine($"{num} is odd");
}
}
}
}
}
n개의 테스트가 주어지고, 각 테스트에 주어진 숫자가 odd(홀수)인지 even(짝수)인지 판단하는 문제이다.
'IT > BaekJoon' 카테고리의 다른 글
[BAEKJOON] 백준 9046: 복호화 (C#) (0) | 2024.08.13 |
---|---|
[BAEKJOON] 백준 11728: 배열 합치기 (C#) (0) | 2024.08.07 |
[BAEKJOON] 백준 14011: Small PhD Restaurant (C#) (0) | 2024.08.05 |
[BAEKJOON] 백준 31846: 문자열 접기 (C#) (0) | 2024.08.05 |
[BAEKJOON] 백준 31775: 글로벌 포닉스 (C#) (0) | 2024.08.03 |