#include "Stdio.h"
main( )
{ int prime( int ) ;
int m,n,i,sum=0,count=0 ;
scanf("%d,%d", &m,&n ) ;
if(m<1 || n>500) printf("Data error!\n");
else
for ( i = m; i <= n ; i ++ ){
if(i<=1) continue;
if ( prime( i ) ==1 ) {count++; sum += i;}
}
printf("count=%d,sum=%d ", count, sum ) ;
return 0;
}
int prime( int n )
{ int i ;
for ( i = 2; i < n ; i ++ )
if ( n % i == 0 ) return ( 0 ) ;
return ( 1 ) ;
}
之前回答不少了http://zhidao.baidu.com/open/question/detail?appid=10002&qid=e73e26c04bfa9324acb6a74b
#include
#include
int prime(int m)
{
int i,k;
if(m<2)
return 0;
k=m/2;
for(i=2;i<=k;i++){
if(m%i==0)
return 0;
}
return 1;
}
int main(void)
{
int m,n,count=0,sum=0;
scanf("%d",&m);
scanf("%d",&n);
for(m;m<=n;m++){
if(prime(m)==1){
count++;
sum=sum+m;
}
}
printf("Count=%d,sum=%d\n",count,sum);
return 0;
}