c语言求1000以内的素数(C语言学习---求一个正整数以内的素数)
#include "stdafx.h"#include <stdlib.h>,我来为大家科普一下关于c语言求1000以内的素数?以下内容希望对你有帮助!
c语言求1000以内的素数
C语言学习 程序练习 求一个正整数以内的素数代码如下:#include "stdafx.h"
#include <stdlib.h>
int main()
{
int i,j=2;
int value;
int prime;
bool flag=false;
scanf_s("%d", &value);
for (i = 2; i < value; i )
{
for (j = 2; j <i; j )
{
prime = i%j;
if (prime == 0)
{ flag = true;
break; }
else
{ flag = false; }
}
if (flag==false && i>=2)
{ printf("this is prime %d in below %d \n",i,value);}
}
system("pause");
return 0;
}
运行结果:
输入100
this is prime 2 in below 100
this is prime 3 in below 100
this is prime 5 in below 100
this is prime 7 in below 100
this is prime 11 in below 100
this is prime 13 in below 100
this is prime 17 in below 100
this is prime 19 in below 100
this is prime 23 in below 100
this is prime 29 in below 100
this is prime 31 in below 100
this is prime 37 in below 100
this is prime 41 in below 100
this is prime 43 in below 100
this is prime 47 in below 100
this is prime 53 in below 100
this is prime 59 in below 100
this is prime 61 in below 100
this is prime 67 in below 100
this is prime 71 in below 100
this is prime 73 in below 100
this is prime 79 in below 100
this is prime 83 in below 100
this is prime 89 in below 100
this is prime 97 in below 100
,免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com