반응형
홀수/짝수 숫자 판단하기 (if문)
#include<stdio.h>
int main(void){
int num;
scanf("%d", &num);
if(num % 2 ) // num % 2 == 1로, '== 1(true)'은 참이기 때문에 생략 가능하다.
printf("%d is a odd number.\n", num);
else
printf("%d is an even number.\n", num);
return 0;
}
반응형
'C' 카테고리의 다른 글
[C언어] 선택 정렬 (Selection Sort) (0) | 2021.06.30 |
---|---|
[C언어] 실습: 배열에서 같은 값 찾기 (0) | 2021.06.28 |
[C언어] 실습: 알파벳 대문자/소문자 판별하기 (0) | 2021.06.25 |
[C언어] 비트 연산 (Letter Attribute) (0) | 2021.06.24 |
[C언어] 실습: 윤년(Leap Year) 판별하기 (조건식) (0) | 2021.06.23 |