- 优先级
#include<iostream>
using namespace std;
int main() {
int x = 2,y = 4, z = 7;
//先x<y,再x--,然后++x,x<z,最后&&
cout << ((x-- < y) && (++x < z)) << "\t" << x << "\t" << y << "\t" << z;
return 0;
} 判断季节: #include<iostream>
using namespace std;
int main() {
int m;
cin >> m;
//"=="优先级高于"||"
if (m == 12 ||m== 1 ||m== 2)cout << "冬季";
else if (m == 3 || m==4 ||m== 5)cout << "春季";
else if (m == 6 || m == 7 || m == 8)cout << "夏季";
else if (m == 9 || m == 10 || m == 11)cout << "秋季";
else cout << "输入错误";
return 0;
} - ?向上取整、向下取整ceil(上)、floor(下)、round(近)、int(舍小数)
#include<iostream>
using namespace std;
int main() {
float x = 2.5;
//实型、整型都可以,int()是舍去小数部分
//ceil(x)向上取整
printf("ceil(%.2f)=%.2f\n", x,ceil(x));
printf("ceil(%.2f)=%.2f\n", -x, ceil(-x));
//floor(x)向下取整
printf("floor(%.2f)=%.2f\n", x, floor(x));
printf("floor(%.2f)=%.2f\n", -x, floor(-x));
//round(x)返回四舍五入到最近的整数值
printf("round(%.2f)=%.2f\n", x, round(x));
printf("round(%.2f)=%.2f\n", -x, round(-x));
return 0;
} oj刷题
也不想给自己找借口,今天只做了一道题,也没学很多C++,就是这样 明天的空闲时间很多,今天像一个转折点,对于学业有了新的认识。 加油!!!一分一秒!!! ?
|