求素数
#include<stdio.h>
#include<math.h>
int prime(int m);
int main(void)
{
int count,m,n,sum;
printf("Enter m:");
scanf("%d",&m);
printf("Enter n:");
scanf("%d",&n);
for(count=0,sum=0;m<=n;m++){
if(prime(m)!=0) {
count++;
sum=sum+m;}
}
printf("count=%d sun=%d\n",count,sum);
return 0;
}
#include<math.h>
int prime(int m);
int main(void)
{
int count,m,n,sum;
printf("Enter m:");
scanf("%d",&m);
printf("Enter n:");
scanf("%d",&n);
for(count=0,sum=0;m<=n;m++){
if(prime(m)!=0) {
count++;
sum=sum+m;}
}
printf("count=%d sun=%d\n",count,sum);
return 0;
}
int prime(int m)
{
int i,y;
if(m==1) return 0;
y=sqrt(m);
for(i=2;i<=y;i++)
if(m%i==0){
return 0;
}
return 1;
}
{
int i,y;
if(m==1) return 0;
y=sqrt(m);
for(i=2;i<=y;i++)
if(m%i==0){
return 0;
}
return 1;
}