1、在屏幕上按每行10个的格式输出100—200间的全部素数,并输出它们的平均值。C语言的

 我来答
BrotherGao
2013-04-17 · TA获得超过1536个赞
知道小有建树答主
回答量:334
采纳率:0%
帮助的人:399万
展开全部

楼主你好!

根据你的要求代码实现如下!

#include <stdio.h>

#include <math.h>

#include<stdlib.h>

int main()

{

int m=100,t=0,i,n=200,sum=0;

double k;

printf("100—200间的全部素数:\n");

for(;m<=n;m++)

{   

 k=sqrt(m);

    for (i=2;i<=k;i++)

    if (m%i==0) break;

 if(i>k){

      printf("%-4d",m);

      sum+=m;

      t++;

      if(t%10==0)printf("\n"); 

 }

 }

printf("\n");

printf("平均值:%6.2f",(float)sum/t);

   return 0;

}

 

希望我的回答对你有帮助!

百度网友f3b3e02
2013-04-17 · TA获得超过2155个赞
知道小有建树答主
回答量:821
采纳率:90%
帮助的人:571万
展开全部
#include "stdio.h"
#include "math.h"
int main()
{
int n,i,j,mark,s;
n=0;
s=0;
for(i=100;i<=200;i++)
{
mark=0;
for(j=2;j<=sqrt(i);j++)
{
if(i%j==0)
{
mark=1;
break;
}
}
if(mark==0)
{
printf("%d\t",i);
s=s+i;
n=n+1;
if(n%10==0)
printf("\n");
}
}
printf("\n100~200之间所有素数的平均数等于:%f",(float)s/(float)n);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
598066456
2013-04-17 · TA获得超过119个赞
知道答主
回答量:146
采纳率:25%
帮助的人:50.5万
展开全部
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
int s=0,tot=0;
for (int i=100;i<=200;i++)
{
bool f=true;
for (int j=2;j<=int(sqrt(i));j++)
if (i%j==0) {f=false;break;}
if (f)
{
printf("%d ",i);
tot++;
if (tot%10==0) printf("\n");
s+=i;
}
}
printf("\n");
printf("%d\n",s/tot);
system("pause");
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
龍__鳳
2013-04-17 · TA获得超过2346个赞
知道小有建树答主
回答量:948
采纳率:0%
帮助的人:1383万
展开全部
#include<stdio.h>
#include<math.h>
void main()
{
int i,n,k,t=0;
double mean,sum=0;
for (i=101;i<=200;i+=2)
{
k=int(sqrt(i));
for(n=2;n<=k;n++)
{
if(i%n==0) break;
}
if (n>=k+1)
{
sum+=i;
t++;
printf("%d ",i);
if(t%10==0)
printf("\n");
}
}
mean=sum/t;
printf("\n%lf %lf\n",sum,mean);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式