1 #include <iostream>
2
3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
4 using namespace std;
5 int main(int argc, char** argv) {
6 //声明整型变量
7 int a,b;
8
9 //从键盘上为整型变量赋值
10 cout<<"a=";
11 cin>>a;
12 cout<<"b=";
13 cin>>b;
14
15 //整型数的算术运算
16 cout<<a<<"+"<<b<<"="<<a+b<<endl;
17 cout<<a<<"-"<<b<<"="<<a-b<<endl;
18 cout<<a<<"*"<<b<<"="<<a*b<<endl;
19 cout<<a<<"/"<<b<<"="<<a/b<<endl;
20 cout<<a<<"%"<<b<<"="<<a%b<<endl;
21
22 //测试溢出
23 short n=32767,m; //n取short类型的最大值
24 cout<<"n="<<n<<endl;
25 m=n+1; //引起溢出
26 cout<<"n+1="<<m<<endl;
27
28 return 0;
29 }