求助,如何用C语言编写程序计算并输出100~300之间全部素数的和?

如题所述

第1个回答  2012-03-22
1楼的把count++;改成count +=m;
然后把循环里的printf去掉,在m循环外printf("%d",count);就好了
第2个回答  2012-03-22
#include <stdio.h>
#include<math.h>
int main (void)
{
int i,m,n,count;
count=0;
for(m=100;m<=200;m++){
n=(int)sqrt(m);
for(i=2;i<=n;i++){
if(m%i==0)break;
}

if(i>n){
printf("%d ",m);
count++;
if(count%10==0)
printf("\n");
}
}
printf("\n");
return 0;
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网