标题:代码出现怪事 素数显示6次
取消只看楼主
达文西
Rank: 1
等 级:新手上路
威 望:1
帖 子:117
专家分:0
注 册:2007-8-4
 问题点数:0 回复次数:1 
代码出现怪事 素数显示6次

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication43
{
class Program
{

public static void Main()
{
int i;
bool x=true;
for (i = 100; i <= 200; i++)
{
for (int j = 2; j <=Convert.ToInt32( Math.Sqrt(i)); j++)
{
if (i % j == 0)
{
x = false;
break;

}

if (x = true)
Console.WriteLine(i);

}


Console.ReadLine();

}
}
}
}
你们看看 比如显示101 101 就出现六次 每个素数都是显示6次 而且必须按enter才显示下一个素数 无限郁闷中


搜索更多相关主题的帖子: 素数 怪事 代码 
2007-08-21 16:26
达文西
Rank: 1
等 级:新手上路
威 望:1
帖 子:117
专家分:0
注 册:2007-8-4
得分:0 
不是六次 是9次  
2007-08-21 16:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-164370-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.209914 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved