学习记录21-10-30:
输入两个自然数,求解区间所有质数的和。
#include<stdio.h>
int main()
{
int x, n, s, y;
printf("Input First and Last natural number = ");
scanf("%d%d", &x, &y);
for (s = 0; x <= y; x++)
{
for (n = 2; n < x && (x%n != 0); n++);
if (n == x)
s = s + x;
}
printf("%d", s);
return 0;
}
无输入检测合理性。