C语言 素数求和

#include <stdio.h>
#include <math.h>
int prime§
{
int a;
if(p<=1)//如果程序中的数值<1,就返回
{
return 0;
}
for(a=2;a<p;a++)
{if(p%a==0)
return 0;
}
return 1;}
int PrimeSum(m, n)
{
int b;
int d=0;
for(b=m;b<=n;b++)
{if(prime(b)!=0)
d+=b;
}
return d;
}
int main()
{
int m, n, p;
scanf("%d %d", &m, &n);
printf(“Sum of ( “);
for( p=m; p<=n; p++ ) {
if( prime§ != 0 )
printf(”%d “, p);
}
printf(”) = %d\n”, PrimeSum(m, n));
return 0;}

猜你喜欢

转载自blog.csdn.net/weixin_43028756/article/details/82961038
今日推荐