#include<stdio.h>
void Snum(int x)
{
int y;
y=x;
if((y%2==0)||(y%1==0))
{
printf("This is not a prime");
}
else
{
printf("%d is a prime ",y);
}
}
int main()
{
int x;
printf("Please input an integer: ");
scanf("%d",&x);
Snum(x);
printf("\n");
return 0;
}
<pre name="code" class="cpp">#include<stdio.h>
int Prime(number)
{
int i;
int flag=1;
for(i=2;i<=number/2;i++)
if(number%i==0)
flag=0;
return(flag);
}
int main()
{
int number;
printf("Please input an interges: ");
scanf("%d",&number);
if (Prime(number))
printf("%d is a prime",number);
else
printf("%d is not a prime",number);
printf("\n");
return 0;
}
判断素数(函数)
最新推荐文章于 2023-11-15 20:02:41 发布