我的模数代码在这里有什么问题? C

问题描述

#include <stdio.h>

int main (void)
{
  int x = 10^2;
  long a = 4000465006540123; //(16 places)
  long b = 4000465006540123 % x;
  
  printf("%li\n",b);
}

当我运行代码(正确编译)时,代码打印为“ 3”。不是应该打印出“ 23”,因为x是100,而不是10?

解决方法

int x = 10^2;int x = 8;相同的^是异或运算符。

使用int x = 100;10*10


注意:在C语言中,% remainder 运算符,而不是 modulus 运算符。 a%b中的Negative resultsa < 0时出现。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...