这是我自己写的一个#include <stdio.h>
#include<math.h>
void close();
int main ()
{
int n,i;
s: printf("Please Input a number:");
if(scanf("%d",&n))
{
if(n == 1)
{
printf("1既不是素数也不是和数!\n");
close;
goto s;
}
else if(n == 2)
{
printf("%d是素数!\n",n);
close;
goto s;
}
else if(n%2==0)
{
printf("%d是和数!\n",n);
close;
goto s;
}
else
{
for(i=3;i<=sqrt
(n);i=i+2)
{
if(n%i==0)
{
break;
}
}
if(i<=sqrt(n))
{
printf("%d是和数!\n",n);
close;
goto s;
}
else
{
printf("%d是素数!\n",n);
close;
goto s;
}
}
}
return 0;
}
void close()
{
char ch;
while((ch = getchar())!='\n');
}
|