2019-11-24 22:40

# 请问一下这个绝对素数的代码编译错误是由于什么原因?

5

#include
#include
int prime(unsigned int);
unsigned int rev(unsigned int);
int main()
{
unsigned int n,m;
scanf("%u",&n);
if(prime(n)!=0)
m=rev(n);
else
{
printf("no\n");
return 0;
}
{
if(prime(m)!=0)
printf("yes\n");
else
printf("no\n");
return 0;
}
int prime(unsigned int x)
{
int i,k;
k=sqrt(x);
for(i=2;i<=k;i++)
{
if(x%i==0)
return 0;
else if(i>k)
return 1;
}
}
unsigned int rev(unsigned int y)
{
unsigned int z=0;
while(y!=0)
{
z=z*10+y%10;
y=y/10;
}
return z;
}
}

• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享
• 邀请回答

#### 2条回答

• ``````#include<stdio.h>
#include<math.h>
int prime(unsigned int);
unsigned int rev(unsigned int);
int main()
{
unsigned int n,m;
scanf("%u",&n);
if(prime(n)!=0)
m=rev(n);
else
{
printf("no\n");
return 0;
}
if(prime(m)!=0)
printf("yes\n");
else
printf("no\n");
return 0;
}
int prime(unsigned int x)
{
int i,k;
k=sqrt((double)x);
for(i=2;i<=k;i++)
{
if(x%i==0)
return 0;
}
return 1;
}

unsigned int rev(unsigned int y)
{
unsigned int z=0;
while(y!=0)
{
z=z*10+y%10;
y=y/10;
}
return z;
}
``````

# 以后提问把原始题目也贴出来

还有，代码要缩进正确，才好阅读。这次帮你都调整了，下次自己要注意

点赞 1 评论 复制链接分享
• 你函数嵌套定义了，你将prime与rev定义在了main函数里，改一下大括号，将prime与rev放在main函数之外

点赞 1 评论 复制链接分享