求商求模运算

2019-04-13 12:14发布

这两种运算总是感觉有点迷糊,现在 拨开乌云见天日。 对于整型数a,b来说,取模运算或者求余运算的方法都是: 1.求 整数商: c = a/b; 2.计算模或者余数: r = a - c*b. #include using namespace std; void div(){ printf("5/3: %d",5/3);cout << endl; printf("5/(-3): %d",5/-3);cout << endl; printf("(-3)/8: %d",-3/5);cout << endl; printf("3/(-8): %d",3/-5);cout << endl; } void mod(){ printf("5取模3: %d",5%3);cout << endl; printf("5取模-3: %d",5%-3);cout << endl; printf("-3取模5: %d",-3%5);cout << endl; printf("3取模-5: %d",3%-5);cout << endl; } void main(){ cout<<"求商运算"<
运算结果: