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

20 lines
282 B
C
Raw Permalink Normal View History

2024-11-20 03:07:17 +00:00
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;
}