新手到来,今天再使用无符号整数时犯了严重的错误,示例如下
unsigned int a = 25335;
unsigned int b = 8898;
unsigned int c = 8945;
int e = b-c;
double d = (double)(int)(b-c)/a;
cout<<e<<endl;
cout<<b-c<<endl;
cout<<d<<endl;
结果如下
对无符号整数进行加减时一定要注意类型转换,不然会得到一些奇奇怪怪的结果,基础一定要加强才行了