萌新求教
//题目:判断101到200之间的素数#include<stream.h>
#include<stdio.h>
#include<math.h>
int main()
{
int x;
int count;
for (x=101;x<=200;x++)
{
for(count=1;count<=floor(sqrt(x))+1;count++)
{if (x/count==0)
cout<<x<<"是质数";}
}
}
为什么运行不了呢,求教,谢谢~ #include<iostream>
#include<math.h>
int main()
{
int x, flag;
int count;
for (x = 100; x <= 200; x++)
{
flag = 1;
for(count = 2; count <= (int)(sqrt((double)x)) + 1; count++)
{
if (x%count == 0)//余,不是除
{
flag = 0;
break;
}
}
if(flag)
std::cout << x << "是质数" << std::endl;
}
return 0;
}
页:
[1]