(!(i % j)) 是否表示不是 i 和 j = 0 的模?

发布于 2024-08-09 20:42:56 字数 327 浏览 2 评论 0原文

int main()
{
 int i,j;

 for (i=1; i<=25; i++)
 {
  for (j=2; j<= i/2; j++)
   if (!(i%j)) break;
  if (j>i/2) cout << i << "\n";
 }
 return 0;
}

这个程序(不是我写的)输出从 1 到 25 的素数,包括 1,尽管 1 不是素数。

我在使用此行时遇到问题: if (!(i%j)) break;

这是否表示“不是 i 和 j = 0 的模数?”

int main()
{
 int i,j;

 for (i=1; i<=25; i++)
 {
  for (j=2; j<= i/2; j++)
   if (!(i%j)) break;
  if (j>i/2) cout << i << "\n";
 }
 return 0;
}

This program (not written by me) outputs the prime numbers from 1 to 25, including 1 even though 1 isnt prime.

I am having trouble with this line: if (!(i%j)) break;

Does this say "not modulus of i and j = 0?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笔芯 2024-08-16 20:42:56

!(i%j)(i%j)==0 相同,即“i 能被 j 整除”

!(i%j) is the same as (i%j)==0, or "i is divisible by j"

做个少女永远怀春 2024-08-16 20:42:56

以下两行本质上是相同的(就逻辑而言):

if (!(i%j))
if ((i % j) == 0)

我阅读第一行以使其更清楚的方式是“如果 i/j 中没有余数”,即, i 可以被 j 整除。

The two following lines are essentially identical (as far as logic goes):

if (!(i%j))
if ((i % j) == 0)

The way I'd read the first line to make it clearer is "if there is not a remainder from i/j", ie, i is divisible by j.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文