2022.12.26
<Coding Test> 1 day
#1 몫 구하기
- 연산자
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int num1, int num2) {
int answer = 0;
answer=num1/num2;
return answer;
}
코딩테스트 연습 - 몫 구하기 | 프로그래머스 스쿨 (programmers.co.kr)
#2 두 수의 곱
- 연산자
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int num1, int num2) {
int answer = 0;
answer=num1*num2;
return answer;
}
코딩테스트 연습 - 두 수의 곱 | 프로그래머스 스쿨 (programmers.co.kr)
#3 두 수의 차
- 연산자
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int num1, int num2) {
int answer = 0;
answer=num1-num2;
return answer;
}
코딩테스트 연습 - 두 수의 차 | 프로그래머스 스쿨 (programmers.co.kr)
#4 나머지 구하기
- 연산자
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int num1, int num2) {
int answer = -1;
answer=num1%num2;
return answer;
}
코딩테스트 연습 - 나머지 구하기 | 프로그래머스 스쿨 (programmers.co.kr)
#5 숫자 비교하기
- if문
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int num1, int num2) {
int answer = 0;
if(num1==num2)
{
answer=1;
}
else
{
answer=-1;
}
return answer;
}
코딩테스트 연습 - 숫자 비교하기 | 프로그래머스 스쿨 (programmers.co.kr)
#6 나이 출력
- 연산자
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int age) {
int answer = 0;
answer=2023-age;
return answer;
}
코딩테스트 연습 - 나이 출력 | 프로그래머스 스쿨 (programmers.co.kr)
#7 두 수의 합
- 연산자
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int num1, int num2) {
int answer = -1;
answer = num1+num2;
return answer;
}
코딩테스트 연습 - 두 수의 합 | 프로그래머스 스쿨 (programmers.co.kr)
#08 각도기
- if 문
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int angle) {
int answer = 0;
if(angle<90)
{
answer=1;
}
else if(angle==90)
{
answer=2;
}
else if(angle<180)
{
answer=3;
}
else if(angle==180)
{
answer=4;
}
return answer;
}
코딩테스트 연습 - 각도기 | 프로그래머스 스쿨 (programmers.co.kr)
위에서 왼쪽부터 순서대로
제한사항에 0보다 큰 정수라는 조건이 있으므로 if조건에 '0보다 크다'라는 범위는 작성하지 않아도 됨.
위에서 부터 연산되기 때문에 위에 해당되는 범위는 아래에 포함시키지 않아도 됨.
#9 두 수의 나눗셈
- 연산자
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int num1, int num2) {
int answer = 0;
answer=num1*1000/num2;
return answer;
}
코딩테스트 연습 - 두 수의 나눗셈 | 프로그래머스 스쿨 (programmers.co.kr)
'programmers' 카테고리의 다른 글
[c programmers] test 23-24 (0) | 2023.01.01 |
---|---|
[c programmers] test 18-22 (0) | 2022.12.31 |
[c programmers] test 17 (0) | 2022.12.29 |
[c programmers] test 15-16 (0) | 2022.12.28 |
[c programmers] test 10-14 (0) | 2022.12.27 |