#include <iostream>
using namespace std;
int main()
{
// + - * / %
int a;
cout<<"请输入第一个数字:";
cin >> a;
int b;
cout<<"请输入第二个数字:";
cin >> b;
int res1 = a+b;
int res2 = a-b;
int res3 = a*b;
int res4 = a/b;
cout << res1 <<" "<<res2<<" "<<res3<<" "<<res4<< endl;
int t;
cin >> t;
return 0;
}
请输入第一个数字:40
请输入第二个数字:10
50 30 400 4
请输入第一个数字:45
请输入第二个数字:10
55 35 450 4
:省略小数,除法运算,两边都是int类型,结果也是int类型
float a;
cout<<"请输入第一个数字:";
cin>>a;
float b;
cout<<"请输入第二个数字:";
cin>>b;
int res1 = a+b;
int res2 = a-b;
int res3 = a*b;
int res4 = a/b;
cout << res1 <<" "<<res2<<" "<<res3<<" "<<res4<< endl;
请输入第一个数字:1.2
请输入第二个数字:0.3
1 0 0 4
:接收输入是float,加减乘除接收的是int,
float a = 7.0;
float b = 2.5;
float res1 = a / b;
cout << res1 << endl; // 输出:2.8
int a=7;
int b=2;
float res1 =a/b;
cout <<res1<<endl; // 输出:3
int res1 = 13 % 5;
//int res2 = 13 %5.1; // C++不允许对小数求余数
int res0=3+3;
int res1=3+7*3;
int res2=(3+7)*3;
int res3=(42/7)*3;
cout<<res1<<" "<<res2<<" "<<res3<<" "<<res0<<endl;
()控制优先级