,在C语言中本质是向0取整
当然对于向0取整我们也可以使用trunc库函数 (需包含math.h头文件)
示例:
#include
#include /...库函数(需包含math.h头文件)
示例:
#include
#include //因为使用了floor函数,需要添加该头文件
int main()
{..., -2.3, round(-2.3), floor(-2.3), ceil(-2.3), trunc(-2.3));
printf(format, -3.8, round(-3.8), floor...-3,python是-4
printf("%d\n", a%d);//C语言中是-1,python是2
return 0;
}
为什么就有差异了呢?...,向-∞方向取整
从而C中%,本质其实是取余;Python中%,本质其实是取模
对任何一个大于0的数,对其进行0向取整和-∞取整,取整方向是一致的,故取模等价于取余
对任何一个小于0的数