Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

jin'space

프로그래머스 lv0 - 사칙연산 (두수의 합 / 두수의 곱 / 두수의 차 / 몫 구하기) 본문

꼼지락

프로그래머스 lv0 - 사칙연산 (두수의 합 / 두수의 곱 / 두수의 차 / 몫 구하기)

진 공간 2023. 5. 6. 11:36

1. 두수의 합 

문제

정수 num1과 num2가 주어질 때, num1과 num2의 합을 return하도록 soltuion 함수를 완성해주세요.

 

제한사항
  • -50,000 ≤ num1 ≤ 50,000
  • -50,000 ≤ num2 ≤ 50,000

입출력 예

입출력 예 설명

입출력 예 #1

  • num1이 2이고 num2가 3이므로 2 + 3 = 5를 return합니다.

입출력 예 #2

  • num1이 100이고 num2가 2이므로 100 + 2 = 102를 return합니다.
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int solution(int num1, int num2) {
    int answer = -1;
    if(num1 >= -50000 && num1 <= 50000 && num2 >= -50000 && num2 <= 50000)
        answer = num1 + num2;
    
    return answer;
}

2. 두수의 차

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int solution(int num1, int num2) {
    int answer = 0;
    if(num1>=-50000 && num1<=50000 && num2>=-50000 && num2<=50000)
        answer = num1-num2;
    return answer;
}

3. 두수의 곱

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int solution(int num1, int num2) {
    int answer = 0;
    if(num1>=0 && num1<=100 && num2>=0 && num2<=100)
        answer = num1 * num2;
    return answer;
}

4. 몫 구하기

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int solution(int num1, int num2) {
    int answer = 0;
        answer = num1/num2;
    return answer;
}

 

'꼼지락' 카테고리의 다른 글

[Js, Javascript] 파일 다운로드 구현  (0) 2023.06.01
블로그에 오신걸 환영합니다 !  (0) 2023.03.25
Comments