본문 바로가기
Baekjoon/단계별로 풀어보기

[단계02] if문 (5문제)

by 해적거북 2020. 12. 16.
728x90

www.acmicpc.net/step/4

 

● [문제번호 1330] 두 수 비교하기

#include <stdio.h>

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

 

● [문제번호 9498] 시험 성적

#include <stdio.h>

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

 

● [문제번호 2753] 윤년

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

 

● [문제번호 14681] 사분면 고르기

#include <stdio.h>

int main(void)
{
    int x, 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 if(x > 0 && y < 0)
        printf("4");
    
    return 0;
}

// 중첩된 if문 쓰면 틀리는 것으로 간주

 

● [문제번호 2884] 알람 시계

#include <stdio.h>

int main(void)
{
    int H, M;
    scanf("%d %d", &H, &M);
    
    if(M < 45)
    {
        H -= 1;
        M = 60 + M - 45;
    }
    else
        M -= 45;
    
    if(H < 0)
        H += 24;
        
    printf("%d %d\n", H, M);
    
    return 0;
}
728x90

댓글