연습장

06. 덧셈식 출력하기 본문

프로그래머스/0단계

06. 덧셈식 출력하기

js0616 2023. 6. 17. 21:14

Q. 두 정수 a, b가 주어질 때 다음과 같은 형태의 계산식을 출력하는 코드를 작성해 보세요.

a + b = c

제한사항

1 ≤ a, b ≤ 100

 

입력

4 5

출력

4 + 5 = 9

 

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];

rl.on('line', function (line) {
    input = line.split(' ');
}).on('close', function () {
    console.log(Number(input[0]) + Number(input[1]));
});

 

 


input[0] = '4' 

input[1] = '5'  라고 볼 수 있다.

 

4 + 5 = 9 // 를 출력하기 위해서

 

4 의 값을 가지는 input[0] 의 값 

+ 문자

5 의 값을 가지는 input[1] 의 값

= 문자

9 의 값을 가지는 input[0] + input[1] 의 값 

 

을 출력해주면된다.

 

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];

rl.on('line', function (line) {
    input = line.split(' ');
}).on('close', function () {
    console.log(Number(input[0]),'+',Number(input[1]),'=', Number(input[0]) + Number(input[1]));
});


 

'프로그래머스 > 0단계' 카테고리의 다른 글

08. 문자열 돌리기  (2) 2023.06.17
07. 문자열 붙여서 출력하기  (0) 2023.06.17
05. 특수문자 출력하기  (0) 2023.06.17
04. 대소문자 바꿔서 출력하기  (0) 2023.06.17
03. 문자열 반복해서 출력하기  (0) 2023.06.16