반응형
CodeUp 기초 100제 51~60번 문제 풀이
CodeUp 기초 100제 - https://codeup.kr/problemsetsol.php?psid=23
[CodeUp] 기초 100제 51~60번 문제 - 현재 글
[1051][기초-비교연산] 두 정수 입력받아 비교하기3


#include <stdio.h> int main(void) { int a, b; scanf("%d %d", &a, &b); if (a <= b) printf("1"); else printf("0"); return 0; }
[1052][기초-비교연산] 두 정수 입력받아 비교하기4


#include <stdio.h> int main(void) { int a, b; scanf("%d %d", &a, &b); if (a != b) printf("1"); else printf("0"); return 0; }
[1053][기초-논리연산] 참 거짓 바꾸기


#include <stdio.h> int main(void) { int a; scanf("%d", &a); printf("%d", !a); return 0; }
- 0은 거짓(false) 1을 포함한 그 외의 숫자는 참 true로 인식된다.
[1054][기초-논리연산] 둘 다 참일 경우만 참 출력하기


#include <stdio.h> int main(void) { int a, b; scanf("%d %d", &a, &b); if (a != 0 && b != 0) { printf("1"); } else { printf("0"); } return 0; }
- &&(and)연산자 : 조건들이 모두 참일 때 true
[1055][기초-논리연산] 하나라도 참이면 참 출력하기


#include <stdio.h> int main(void) { int a, b; scanf("%d %d", &a, &b); if (a != 0 || b != 0) { printf("1"); } else { printf("0"); } return 0; }
- ||(or)연산자 : 조건중 하나라도 참 이면 true
[1056][기초-논리연산] 참거짓이 서로 다를 때에만 참 출력하기


#include <stdio.h> int main(void) { int a, b; scanf("%d %d", &a, &b); printf("%d", (a && !b) || (!a && b)); return 0; }
[1057][기초-논리연산] 참거짓이 서로 같을 때에만 참 출력하기


#include <stdio.h> int main(void) { int a, b; scanf("%d %d", &a, &b); printf("%d", (a && b) || (!a && !b)); return 0; }
[1058][기초-논리연산] 둘 다 거짓일 경우만 참 출력하기


#include <stdio.h> int main(void) { int a, b; scanf("%d %d", &a, &b); printf("%d", (!a && !b)); return 0; }
[1059][기초-비트단위논리연산] 비트단위로 NOT 하여 출력하기


#include <stdio.h> int main(void) { int a; scanf("%d", &a); printf("%d", ~a); return 0; }
- 비트단위 논리연산
~(bitwise not) / &(bitwise and) / |(bitwise or) / ^(bitwise xor) / <<(bitwise left shift) / >>(bitwise right shift) - ~(bitwise not)
1 = 00000000 00000000 00000000 00000001
~1 = 11111111 11111111 11111111 11111110 = -2
[1060][기초-비트단위논리연산] 비트단위로 AND 하여 출력하기


#include <stdio.h> int main(void) { int a, b; scanf("%d %d", &a, &b); printf("%d", a & b); return 0; }
&(bitwise and)
3 = 00000000 00000000 00000000 00000011
5 = 00000000 00000000 00000000 00000101
3 & 5 = 00000000 00000000 00000000 00000001
반응형
'Programming > C' 카테고리의 다른 글
[CodeUp] 기초 100제 71~80번 문제 (0) | 2019.12.28 |
---|---|
[CodeUp] 기초 100제 61~70번 문제 (0) | 2019.12.28 |
[CodeUp] 기초 100제 41~50번 문제 (0) | 2019.12.28 |
[CodeUp] 기초 100제 31~40번 문제 (0) | 2019.12.28 |
[CodeUp] 기초 100제 21~30번 문제 (0) | 2019.12.28 |
댓글