简单的小程序,但我找不出它的错误
# include <stdio.h>int main()
{
int m,n,r;
n=2;
scanf("m=%d",&m);
while (n<=m/2)
{
r=m%n;
n=n+1;
}
if(r=0) printf("not prime\n");
else printf("prime\n");
return 0;
}
# include <stdio.h> int main() { int m, n, r; n = 2; scanf("%d",&m); // 去掉了"m=",要不然在输入的时候必须按格式输入"m=" while (n <= m/2) //取m/2这个范围是不准确的,可以自行查阅素数算法,看懂即可 { r = m%n; if(r == 0) //找到其它因数是跳出循环 break; n = n + 1; // 可以写成n++; } if(n == (m/2)+1) // "="是赋值,"=="才是比较相等的意思 { printf("prime\n"); } else { printf("not prime\n"); } system("pause"); // VS2012中只警告,我就没有添加 #include<stdlib.h>或#include<windows.h> return 0; }