完善下列程序#include <stdio.h> int hws(long n) { long x=n,t=0,k; while(x>0) { k=x%10; t = t*10 + k; x=x/10; } if( _____①______) return 1; else return 0; } int main(void) { long k,s=0; for(k=200; k<=2000;k++) if(____②_______) s=s+k; printf("%ld ",s); return 0; }
时间: 2023-12-24 17:06:12 浏览: 61
完善后的程序如下:
```c
#include <stdio.h>
int hws(long n) {
long x = n, t = 0, k;
while (x > 0) {
k = x % 10;
t = t * 10 + k;
x = x / 10;
}
if (t == n) return 1;
else return 0;
}
int main(void) {
long k, s = 0;
for (k = 200; k <= 2000; k++) {
if (hws(k)) s = s + k;
}
printf("%ld ", s);
return 0;
}
```
其中,第一个空(①)的答案应该为 `t == n`,即判断翻转后的数是否和原数相等。
第二个空(②)的答案应该为 `hws(k)`,即判断数 k 是否为回文数,是的话就将其加到累加器 s 中。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![c](https://img-home.csdnimg.cn/images/20250102104920.png)
![image/gif](https://img-home.csdnimg.cn/images/20210720083352.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![text/x-c](https://img-home.csdnimg.cn/images/20250102104920.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![exe](https://img-home.csdnimg.cn/images/20241231044909.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![text/x-c](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![h](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)