【问题标题】:What's wrong with my code with modulus here? (C) [duplicate]我的模数代码有什么问题? (C) [重复]
【发布时间】:2020-08-13 06:19:04
【问题描述】:
#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?

【问题讨论】:

  • ^ 不是 C 中的幂运算符。它是按位异或。进行基本调试。至少打印出要检查的值。

标签: c modulus


【解决方案1】:

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

使用int x = 100;10*10


注意:在 C 中,%余数 运算符,而不是 模数 运算符。 Negative resultsa%b 发生在 a &lt; 0 时。

【讨论】:

  • 谢谢!!!!!!
猜你喜欢
  • 2017-05-02
  • 1970-01-01
  • 2015-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多