Input Stream
#include <iostream> // cout , cin 이 있는 라이브러리
using namespace std;
int main() {
int x,y,sum,mult,mod ;
float div;
cin >> x >> y; // cin : 키보드로부터 값을 입력받음
sum = x+y;
mult = x*y;
div = x / y; div = float(x) / y;
mod = x % y;
cout << x << '\t' << y << endl;
cout << sum << endl;
cout << mult << endl;
cout << div << endl; // 정수랑 정수를 대입할 떄 항상 정수로 나오게된다 -> 하나를 실수로 바꿔주면 문제해결됨
cout << mod << endl;
Arithmetic Operators
#include <iostream> // cout , cin 이 있는 라이브러리
using namespace std;
int main() {
int x = 10, y =20 ;
x += y ; // = x + y;
x %= y; // = x % y;
x = 20;
cout << x++ << endl; // stat. -> x를 1 증가
cout << ++x << endl; // x를 1증가 -> stat.
int main () {
cout << ( 7 >= 5) << endl;
cout << (7 == 5) << endl;
cout << ( 7 != 5) << endl;
cout << (7 >=5 ? 참 : 거짓) << endl;
(7 >= 5 ? 1000 : -1000)로 변환가능
참이면 1 거짓이면 0 (0 이외에는 모든 숫자를 참으로 판단)
x = 2 + 4 - 7 -> x = 6 - 7 -> x = -1 (left to right)
해당 자료는 경희대학교 소프트웨어융합학과 배성호교수님 수업내용을 참조하였습니다.
'Code > C++' 카테고리의 다른 글
[C++] Local & Global Variables/ Pass by reference & value/ Recursion (0) | 2019.09.29 |
---|---|
[C++] Function/ cmath library/ Default argument (0) | 2019.09.28 |
[C++] Variables, Floating-Point, Character (0) | 2019.09.28 |
[C++] break / continue / for/ switch statement (0) | 2019.09.23 |
[C++] Boolean/IF 구문 / 명령문 (0) | 2019.09.18 |