코딩로그
[백준/BOJ/C++] 10480번 Oddities 본문
[문제]
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.
[Source Code]
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
int test;
cin >> test;
int *arr = new int[test];
for(int i = 0; i <test; i++){
int input;
cin >> input;
arr[i] = input;
}
for(int i = 0; i < test; i++){
cout << arr[i] <<" is ";
if(arr[i] % 2 == 0)
cout << "even\n";
else
cout << "odd\n";
}
}
[결과 화면]
'YJ > C++' 카테고리의 다른 글
[백준/BOJ/C++] 2954번 창영이의 일기장 (0) | 2021.10.29 |
---|---|
[백준/BOJ/C++] 10829번 이진수 변환 (0) | 2021.10.29 |
[백준/BOJ/C++] 2720번 세탁소 사장 동혁 (0) | 2021.10.29 |
[백준/BOJ/C++] 10103번 주사위 게임 (0) | 2021.10.29 |
[백준/BOJ/C++] 9325번 얼마? (0) | 2021.10.29 |