求素数问题

来源:互联网 发布:外汇软件哪个好 编辑:程序博客网 时间:2024/06/03 19:02
这是一个比较简单的问题,我却在前几天的一次考试中没有写出来。
#include "math.h"#include <string.h>#include <stdio.h>int main(int argc, char *argv[]){int m ,i ,k, h = 0, leap = 1;for(m = 101;m <= 200; m++){k = sqrt(m + 1);for(i = 2;i <= k; i++)if(m%i == 0){leap = 0;break;}if(leap){printf("%-4d\n",m);h++;if(h%10 == 0)printf("\n");}leap = 1;}//printf("\n the total is %d\n", h//);//printf("%d\n", h); }


原创粉丝点击