#include
#inlcude
void main(){
int m, k;
puts("please input the number:");
scanf_s("%d", &m);
printf("the prime numbers include as following: ");
for (int j = 1; j <= m; j++) {
k = sqrt(j);
for (int i = 2; i <= k+1; i++) {
if (j%i == 0) {
break;
}
if (i == k + 1) {
printf("%d ", j);
}
}
}
}
输入值是100就可以求100以下的质数,为了你方便我没有把数字写死。
#include
#include
int f(int n)
{if(n<2)return 0;
int i;
for(i=2;i<=n/2;i++)
if(n%i==0)
return 0;
return 1;
}
int main()
{int i;
for(i=1;i<=100;i++)
if(f(i))
printf("%5d",i);
system("pause");
}