컴공댕이 공부일지
#3. 조건 본문
728x90
1) 두 수 비교하기
백준 1330번
#include <stdio.h>
int main() {
int a,b=0;
scanf("%d %d", &a, &b);
if(a>b) {
printf(">");
} else if (a<b) {
printf("<");
} else {
printf("==");
}
return 0;
}
2) 시험 성적
백준 9498번
#include <stdio.h>
int main() {
int g=0;
scanf("%d", &g);
if(g>=90 && g<=100) {
printf("A");
} else if (g>=80 && g<=89) {
printf("B");
} else if (g>=70 && g<=79) {
printf("C");
} else if (g>=60 && g<=69) {
printf("D");
} else {
printf("F");
}
return 0;
}
3) 사분면 고르기
백준 14681번
#include <stdio.h>
int main() {
int x,y=0;
scanf("%d", &x);
scanf("%d", &y);
if(x>0 && y>0) {
printf("1");
} else if (x<0 && y>0) {
printf("2");
} else if (x<0 && y<0) {
printf("3");
} else {
printf("4");
}
return 0;
}
4) 윤년
백준 2753번
#include <stdio.h>
int main() {
int x=0;
scanf("%d", &x);
if(x%4==0 && x%100!=0 || x%400==0) {
printf("1");
} else {
printf("0");
}
return 0;
}
5) 사파리 월드
백준 2420번
#include <stdio.h>
int main() {
long long n,m=0;
scanf("%lld %lld",&n, &m);
if(n>=m) {
printf("%lld",n-m);
} else {
printf("%lld",m-n);
}
return 0;
}
백준에서 매번 변수 타입때문에 틀리는데... 타입형 공부를 더 해야하나... 모지...ㅎㅅㅎ
728x90
'문제 풀이 > 백준 새싹문제 풀이 모음' 카테고리의 다른 글
#2. 입력과 계산 (0) | 2022.08.31 |
---|---|
#1. 출력 (0) | 2022.08.31 |
Comments