본문 바로가기
알고리즘 스터디/코드업 기초100제 - C

[CodeUp] 코드업 기초 100제 C - 문제 1033~1042 - 비프시프트 연산, 비교연산

by 레일라오리덕 2021. 5. 11.
728x90

[1043 문제]

 

#include <stdio.h>

main(){
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d", a%b);
}

 

[1044 문제]

 

#include <stdio.h>

main(){
    long a;
    scanf("%ld", &a);
    printf("%ld", ++a);
}

 

[1045 문제]

 

#include <stdio.h>

main(){
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n%d\n%d\n%d\n%d\n%d\n", a+b, a-b, a*b, a/b, (double)a/(double)b);
}

 

728x90

 

 

[1046 문제]

 

#include <stdio.h>

main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int result = a+b+c;
    printf("%d\n%.1f", result, (double)result/3);
}

 

[1047 문제]

 

#include <stdio.h>

main(){
    int a;
    scanf("%d", &a);
    printf("%d", a<<1);
}

 

2진수 형태로 저장되어 있는 값들을 왼쪽(<<) 이나 오른쪽(>>)으로 지정한 비트 수만큼 밀어주면 2배씩 늘어나거나 반으로 줄어드는데, 왼쪽(<<)은 오른쪽에 0이 주어진 개수만큼 추가되고, 오른쪽(>>)은 왼쪽에 0이나 1이 개수만큼 추가된다(음수인 경우)

 

 

[1048 문제]

 

#include <stdio.h>

main(){
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d", a<<b);
}

 

1047문제에서 설명했던대로 a의 b승을 한 값이 출력된다.

 

[1049 문제]

 

#include <stdio.h>

main(){
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d", a>b);
}

 

[1050 문제]

 

#include <stdio.h>

main(){
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d", a==b);
}

 

[1051 문제]

 

#include <stdio.h>

main(){
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d", a<=b);
}

 

[1052 문제]

 

#include <stdio.h>

main(){
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d", a!=b);
}

 

 

728x90

댓글