这样编不太好
#include
void main()
{
void shusu_(int z);
int n;
printf("please enter n:\n");
scanf("%d",&n);
shusu_(n);
}
void shusu_(int z)
{
int i;
if(z==2||z==1)
printf("this is shusu\n");
else
for(i=z-1;i>2;i--)
{
if(z%i==0)
{
printf("this is wrong\n");
break;
}
else if(i==3)
{
printf("rhis is shusu\n");
}
}
}
两条语句以上要用花括号
#include
void main()
{
void shusu_(int z);
int n;
printf("please enter n:\n");
scanf("%d",&n);
shusu_(n);
}
void shusu_(int z)
{
int i,flag=1;
if(z==2||z==1)
printf("this is shusu\n");
else
{ for(i=z-1;i>2;i--)
{
if(z%i==0)
{flag=0;break;
}
}
if(flag)
printf("this is shusu\n");
else
printf("this is wrong\n");
}
}
//在你的基础上稍微修改了一些
#include
void main()
{
void shusu_(int z);
int n;
printf("please enter n:\n");
scanf("%d",&n);
shusu_(n);
}
void shusu_(int z)
{
int i;
if(z==2||z==1)
printf("this is shusu\n");
else
for(i=z-1;i>1;i--)
{
if(z%i==0)
{ printf("this is 偶数\n"); break;}
}
if(i==1)
printf("rhis is shusu\n");
}
void shusu_(int z)
{
int i;
if(z==2||z==1)
printf("this is shusu\n");
else
for(i=z-1;i>2;i--)
{
if(z%i==0)
{ printf("this is wrong\n"); break;}//错在这里
else
printf("rhis is shusu\n");
}
}
else 没有跟if对上
你这个求素数的算法也错了