본문 바로가기
c++/프로그래머스

[프로그래머스] 덧셈식 출력하기(c++)

by ilp 2023. 12. 26.
반응형

https://school.programmers.co.kr/learn/courses/30/lessons/181947

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr



#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int a,b;
    cin>>a>>b;
    cout<<a<<" + "<<b<<" = "<<a+b;
    return 0;
}

 

cin으로 입력받고

cout으로 출력해주었다.

출력할때 a+b를 변수에 넣어서 출력할 수 도 있지만

a+b값을 변수로 만들지 않고 출력을 할 수 도 있다.

ex)

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int a,b;
    cin>>a>>b;
    int answer=a+b;
    cout<<a<<" + "<<b<<" = "<<answer;
    return 0;
}

 
반응형