整数才可以求余,求余后的符号位与左边数相同。
例:
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
整数才可以求余,求余后的符号位与左边数相同。
例:
5%2=1 5%-2=1 -5%2=-1 -5%-2=-1
#include<iostream>
using namespace std;}
运行结果:
1
1
-1
-1
Press any key to continue