1、在屏幕上按每行10个的格式输出100—200间的全部素数,并输出它们的平均值。C语言的
4个回答
展开全部
楼主你好!
根据你的要求代码实现如下!
#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;
}
希望我的回答对你有帮助!
展开全部
#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);
}
#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);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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");
}
#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");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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);
}
#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);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询