c语言入门求教
键盘输入正整数,判断数据是否为素数,直到输入0为止。怎么实现输入0为止
#include <stdio.h>
#include<math.h>
main()
{
int m, i, k;
scanf("%d", &m);
while (m != 0)
{
k = sqrt(m);
for (i = 2; i <= k; i++)
if (m % i == 0)
break;
if (i >= k + 1)
printf("%d is a prime number\n", m);
else
printf("%d is not a prime number\n", m);
return m;
}
}