关于求余的符号位

来源:互联网 发布:同时删除多个表的数据 编辑:程序博客网 时间:2024/06/08 08:03

      整数才可以求余,求余后的符号位与左边数相同。

例:

5%2=1       5%-2=1       -5%2=-1       -5%-2=-1


#include<iostream>

using namespace std;




int main()
{
   cout<<5%2<<endl;
   cout<<5%-2<<endl;
   cout<<-5%2<<endl;
   cout<<-5%-2<<endl;


return 0;

}


运行结果:

1
1
-1
-1
Press any key to continue



原创粉丝点击