一个质数。在大于1的自然数中,除1和100整数本身外,不能被任何其他自然数整除的次数。素数在数论中起着重要的作用。
大于1但没有质数通道的数称为合数。1和0既不是质数也不是合数。
通过滤波法得到的100以内质数的源代码如下:
#include"stdio.h"
main()
main()
{
IntI,j。
对于(I = 2我<99我+ +)
{
对于(j = 2<我J + +)
{
If(I%j==0)
{
打破;
}
如果(j==I-1)
{
Printf(“%4d”,I);
}
扩展资料:
100以内的数字代码如下
包含<bits/stdc++。H >
使用命名空间性病。
Intthesum(Intn)
{
返回(n/10+n%10%)+(10)(n/10%*(n%10));
}
Intmain(){
Intn=100;
For (int I = 10I <= n我+ +)
{
If (sum (I) = = I) cout <<I <<endl
}
返回0;
}
源代码如下:
#include <stdio.h>
#include <math.h>
int main()
{
int a, b, i, flag
printf("输入两个整数: ")
scanf("%d %d", &a, &b)
printf("%d与%d之间的素数为: ", a, b)
while(a<b)
{
flag=0
for(i=2i<=sqrt(a)i++)
{
if(a%i==0)
{
flag=1
break
}
}
if(flag==0)
printf("%d ", a)
a++
}
return 0
}
扩展资料
一个偶数总能表示为两个素数之和的源代码如下:
#include "stdio.h"
#include "math.h"
main()
{
int a,b,c,d
scanf("%d",&a)
for(b=3b<=a/2b+=2)
{
for(c=2c<=sqrt(b)c++)
if(b%c==0) break
if(c>sqrt(b))
d=a-b
else
break
for(c=2c<=sqrt(d)c++)
if(d%c==0)
break
if(c>sqrt(d))
printf("%d=%d+%d\n",a,b,d)
}
}
for(int i=5i<=sqrt(x)i+=6)
if(x%i==0||x%(i+2)==0)
{
printf("%d不是素数",x)
return 0
}
printf("%d是素数",x)
return 0
}