今天突然有点时间,这个是有两位精度的平均数:
#include <stdio.h>
int main()
{
int a,b,max,mix,i,j,s,l,k;
float average,s1,l1;
st:
printf("\nPlease enter two numbers:");
scanf("%d,%d",&a,&b);
s=0;l=0;
if (a>b)
{
max=a;
mix=b;
}
else
{
max=b;
mix=a;
}
for(i=mix;i<=max;i++)
{
for(j=2;j<=i;j++)
if (i%j==0)
{
if (i!=j)
printf("\n%d:",i);
for(k=2;k<i;k++)
{
if (i%k==0)
printf("%d ",k);
}
break;
}
if (i==j)
{
s=s+i;
l=l+1;
printf("\n%d:prime",i);
}
}
s1=s;l1=l;
average=s1/l1;
printf("\nThere are %d prime numbers.\n",l);
printf("The average value of the prime numbers is %.2f .",average);
goto st;
getche();
}