int sushu(int n)
{
int i = 0;
for ( i = 2; i <= sqrt(n); i++)
{
if (n % i == 0)
{
return 0;
}
}
return 1;
}
int main()
{
int num = 0;
printf("please input a num:");
scanf("%d", &num);
if (sushu(num) == 1)
{
printf("%d is a sushu\n", num);
}
else
{
printf("%d is not a sushu\n", num);
}
return 0;
}
问题梳理:
1.在for循环中忘记给i赋初值;
2.scanf中忘记加上&