#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main() { int a,b,i,j,temp; while(scanf("%d %d",&a,&b)!=EOF){ int sum=0; if(a>b){ temp=a; a=b; b=temp; } for(i=a+1;i<b;i++){ int flag=0; for(j=2;j<=sqrt(i);j++){ if(i%j==0){ flag=1; break; } } if(flag==0){ sum=sum+i; } } printf("%d\n",sum); } } |
Double click to view unformatted code.