코딩해요/C

[백준/C언어] 조건문 문제풀이

yenas0 2023. 7. 11. 22:59
반응형

 

#1330번/ 두 수 비교하기

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	scanf("%d %d", &a, &b);
	if (a > b)
		printf(">");
	else if (a < b)
		printf("<");
	else
		printf("==");

	return 0;
}

 

 




#9498번/ 시험 성적

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	int score;
	scanf("%d", &score);
	if (score <= 100 && score >= 90)
		printf("A");
	else if (score >= 80 && score <= 89)
		printf("B");
	else if (score >= 70 && score <= 79)
		printf("C");
	else if (score >= 60 && score <= 69)
		printf("D");
	else
		printf("F");
	return 0;
}

 

 





#2753번/ 윤년

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	int year;

	scanf("%d", &year);
	if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
		printf("1");
	else
		printf("0");

	return 0;
}

연산자때문에 좀 고민한 문제..  연산 순서 생각해서 if문 작성해야 함

 





#14681번/ 사분면 고르기

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	int x;
	int y;

	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;
}

 

 

 





#2884번/ 알람 시계

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	int hour;
	int min;

	scanf("%d %d", &hour, &min);

	if (min >= 45)
		printf("%d %d", hour, min - 45);

	else if (hour == 0 && min < 45)
		printf("23 %d", min + 15);

	else if (hour !=0 && min<45)
		printf("%d %d", hour - 1, min + 15);

	return 0;
}

 

 





#2525번/ 오븐 시계

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	int hour;
	int min;
	int time;

	scanf("%d %d", &hour, &min);
	scanf("%d", &time);

	if (min + time < 60)
		printf("%d %d", hour, min + time);

	else if ((hour + (min + time) / 60) >= 24)
		printf("%d %d", (hour + (min + time) / 60) - 24, (min + time) % 60);
	
	else	
		printf("%d %d", hour + (min + time) / 60, (min + time) % 60);

	return 0;
}

 

 

 





#2480/ 주사위 세개

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;

	scanf("%d %d %d", &a, &b, &c);

	if (a == b && b == c)
		printf("%d", 10000 + a * 1000);

	else if (a != b && b != c && c != a) {
		int max = a;
		if (max < b)
			max = b;
			if (max < c)
				max = c;
		else if (max>b && max < c)
			max = c;

		printf("%d", max * 100);
	}
	else {
		if (a == b)
			printf("%d", 1000 + a * 100);
		else if (b == c)
			printf("%d", 1000 + b * 100);
		else
			printf("%d", 1000 + c * 100);
	}
	return 0;
}




 

반응형