第一道例题
第二道例题/********************************* ** 功能:布尔类型使用举例 ** *********************************/ #include<iostream> using namespace std; int main() { bool flag = true; cout<<flag<<endl; cout<<boolalpha<<flag<<endl; cout<<flag + 5<<endl; flag = 0; cout<<"执行语句flag=0;后flag的值为:"<<boolalpha<<flag<<endl; flag = 0.0; cout<<"执行语句flag=0.0;后flag的值为:"<<boolalpha<<flag<<endl; return 0; }
# include<iostream>using namespace std;int main(){short i, j, m, n;i = 1000;j = 1000;m = i + j;n = i * j;cout<<"m = "<<m<<endl;cout<<"n = "<<n<<endl;return 0;}第三道例题
第四道例题# include<iostream> using namespace std; int main() { int i = 6, j, k, temp; j = ++i; k = i++; ++i = 1; cout<<"i = "<<i<<endl <<"j = "<<j<<endl <<"k = "<<k<<endl; return 0; }
第五道例题# include<iostream> using namespace std; int main() { char ch; cout<<"please input a character: "; cin>>ch; ch = ch>= 'a'&&ch<= 'z'?ch - 'a' + 'A' : ch; //上述语句等价于ch = ch>= 'a'&&ch,= 'z '?ch - 32 : ch; cout<<"The result is: "<<ch<<endl; return 0; }
# include<iostream> using namespace std; int main() { int ab, ac; double b = 3.14; char c = 'A'; ab = int(b); ac = int(c); cout<<"b = "<<b<<endl; cout<<"ab="<<ab<<endl; cout<<"c ="<<c<<endl; cout<<"ac = "<<ac<<endl; return 0; }
第三周作业
最新推荐文章于 2024-09-20 19:38:39 发布