


代码: 全选
#include<stdio.h>
#include<math.h>
void main()
{
int a,c,i,k,b=1;
float f=0,g;
printf("This is the program for prime number\n");
printf("-----------------------------------------------------------------\n");
printf("Please input the number \n");
scanf("%d",&a);
printf("-2-");
for(i=3;i<=a;i++)
{
f=sqrt(i);
c=0;
for(k=2;k<=f;k++)
{
c=!(i%k)+c;
}
if(c==0)
{
printf("-%d-",i);
b++;
}
}
g=(float)b/a;
printf("\nThe total is %d !\nThe rate of prime number is %8.4f %\n",b,100*g);
printf("-----------------------------------------------------------------\n");
}
我在8楼回答你了啊……wshn13 写了:有人回答吗 啊啊啊啊啊