您的位置:首页 > 其它

8.2写一个判断素数的函数,在主函数输入一个整数,输出是否是素数的消息。

2012-02-29 20:16 639 查看
View Code

#include<stdio.h>
#include<math.h>
int psushu(int m)
{
int i=2,t=0;
for(;i<=m;i++)
{
if(m%i==0&&i<m)
break;
if(m-i==0)
t=1;
}
return t;
}
void main()
{
int a,s;
printf("enter shu is \n");
scanf("%d",&a);
s=psushu(a);
if(s==1) printf("%d is sushu\n",a);
else printf("%d is not sushu\n",a);
}


8.2写一个判断素数的函数,在主函数输入一个整数,输出是否是素数的消息。
psushu(m)
{int i=m,t;
for(;i<=m;i++)
if(m%i==0&&i<m) breac;
if(m-i==0) t=1;
else t=0
return m;
}
main()
{int a,s;
printf("enter sushu is \n");
scanf("%d",&a);
s=psushu(a);
if(s=1) printf("a is sushu\n");
else printf("s is not sushu\n");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐