#include<iostream>
using namespace std;
int main() {
int a1 = 10;
int b1 = 3;
cout << a1 + b1 << endl;
cout << a1 - b1 << endl;
cout << b1 - a1 << endl;
cout << a1 * b1 << endl;
cout << a1 / b1 << endl;//两个整数相除,结果依然是整数,将小数去除
float a2 = 10.0f;
float b2 = -3.0f;
cout << a2 / b1 << endl;//3.3333
cout << a2 / b2 << endl;//-3.3333
// 取模运算
cout << a1 % b1 << endl;
//前置递增 ++ 先让变量+1,然后进行表达式运算
int a = 10;
int b = ++a * 10;
cout << "a=" << a << endl;
cout << "b=" << b << endl;
//后置递增 ++ 先进性表达式计算,后变量+1
int a3 = 10;
int b3 = a3++ * 10;
cout << "a3=" << a3 << endl;
cout << "b3" << b3 << endl;
system("pause");
return 0;
}
算数运算符
最新推荐文章于 2024-08-16 16:51:12 发布