#include<iostream> using namespace std; int main() { int day; cin >> day; switch (day) { case 1: case 2: case 3: case 4: case 5:cout << "workday. Let’s work hard" << endl; break; case 6: case 7:cout << "weekend. Let’s have a rest." << endl; break; default:cout << "Day out of range Sunday...Saturday" << endl; break; } return 0; }
#include<iostream> using namespace std; int main() { int n, i, j = 0, digit = 0, right_digit = 0, t; cout << "Enter the number:"; cin >> n; cout << "The number in reverse order is"; t = n; do { n /= 10; digit += 1; } while (n != 0); n = t;//复位 for (i =digit;i>0;i--){ j=n % 10; n /= 10; right_digit += j * pow(10, i - 1); } cout << right_digit<< endl; return 0; }
代码写完后再看就觉得简单多了,但是实际刚才做的时候遇到了许多困难,然后一一解决才最终完成
应该是我还不太熟练吧,接下来需要多加练习
第二题复位这一步开始没写,导致结果是0,这需要注意
计算正确数字时位数是乘10的(n-1)次,也需要注意