1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-23 15:48:42 +00:00
202401-programming-assignments/【实践课外】10.函数1/6-6 使用函数求素数和.c

20 lines
282 B
C

int prime(int p) {
if (p <= 1) return 0;
for (int i = 2; i * i <= p; i++) {
if (p % i == 0) return 0;
}
return 1;
}
int PrimeSum(int m, int n) {
int sum = 0;
for (int i = m; i <= n; i++) {
if (prime(i)) sum += i;
}
return sum;
}