In C language, there are five arithmetic operators (+, -, *, /, %). Their usage syntax remains unchanged in C++. The first four addition, subtraction, multiplication and division are no different from what we have learned in mathematics since childhood, except %. We need to relearn the modulus, which means taking the remainder. For example, the result of 20%8 is 4, and the operands on both ends of % must be integers.
Since the knowledge syntax has basically not changed, we will focus on practical program demonstrations in this part.
For example, if there are 1670 questions in the training field and the number of digits is split, we can implement it in C++ as follows:
#include<iostream>usingnamespacestd;intmain(){inta;//The three-digit number to be judged intge;//The ones digit in the three-digit number intshi;//The tens digit in the three-digit number intbai;//Three digits The hundreds digit in the number cin>>a;ge=a%10;shi=a%100/10;bai=a/100;cout<<ge<<<<shi<<<<bai<<endl;return0; }
Please type the code on your own computer and submit question 1670. Only if you are correct can you continue.
Similarly, after completing question 1007, we still use C++ to complete it. The code is as follows:
#include<iostream>usingnamespacestd;intmain(){intx,y;cin>>x;if(x<1){y=x;}elseif(1<=x&&x<10){y=2*x-1; }else{y=3*x-11;}cout<<y<<endl;return0;}
The running results are as follows:
Everyone still pays attention to the usage scenarios of the logical operator &&, and do not write consecutive words like 1<=x<10!
Okay, please go to the computer and type the code yourself and submit question 1007 correctly before continuing to study!