C++整数相除、取模运算和自加
#include<iostream> using namespace std; int main() { int num1 = 30; int num2 = 4; cout << num1 / num2 << endl; //整数除以整数结果还是整数,小数点之后的都去掉 int a1 = 20; int a2 = 3; cout << a1 % a2 << endl; //取模运算的本质是求余数 int b1 = 10; int b2 = 3; int b3 = b1++ +10; //b1++先计算表达式,再进行变量自加 int b4 = ++b2 + 10; //b2++先进行变量自加,再计算表达式 cout << b3 << endl; cout << b1 << endl; cout << b4 << endl; cout << b2 << endl; system("pause"); return 0; }