#include<stdio.h> #define N 100 int get_sum(int small,int big);//求a b之间的质数和 int judge(int n);//判断是否是质数,是返回1 否返回0 int main(void){ int a,b,i=0; int sample[N][2]; int sum = 0; while(scanf("%d%d",&a,&b) == 2){ sample[i][0] = a; sample[i][1] = b; ++i; } for(int j = 0;j < i;++j){ sum = get_sum(sample[j][0],sample[j][1]); printf("%d\n",sum); } return 0; } int judge(int n){ if(n <= 1) return 0; for(int i = 2;i <= n;++i){ if((n%i) == 0) break; } if(i == n) return 1; else return 0; } int get_sum(int small,int big){ int sum = 0; for(int i = small +1 ;i < big; ++i){ if(judge(i)) sum+=i; } return sum; } /* Main.c: In function 'judge': Main.c:29:6: error: 'i' undeclared (first use in this function) if(i == n) ^ Main.c:29:6: note: each undeclared identifier is reported only once for each function it appears in Main.c:33:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ */ |
Double click to view unformatted code.