mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-27 14:36:19 +00:00
20 lines
282 B
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;
|
||
|
}
|