diff --git a/2207/C语言同步练习源码/2.循环结构-4.c b/2207/C语言同步练习源码/2.循环结构-4.c new file mode 100644 index 0000000..c004d19 --- /dev/null +++ b/2207/C语言同步练习源码/2.循环结构-4.c @@ -0,0 +1,20 @@ +#include + +int main(){ + + int i, s, t;//i, s洢λ,tǽȡλ֮ + for(i=1;i<9999;i++){ + t = i; + while(t > 0){ + s = (t/10==0?1:(t/100==0?2:(t/1000==0?3:4)));//λ + t = i%(int)pow(10, s-1);//ʹģȥλ + if(t*t == i){ + printf("%d:%d\n", t, i); + } + } + } + + + + return 0; +} diff --git a/2207/C语言同步练习答案.md b/2207/C语言同步练习答案.md index 3b18212..0435360 100644 --- a/2207/C语言同步练习答案.md +++ b/2207/C语言同步练习答案.md @@ -253,6 +253,26 @@ int main(){ ![image-20250220231000056](https://yp.smallkun.cn/markdown/image-20250220231000056.png!compress) ```c +#include + +int main(){ + + int i, s, t;//i用来遍历所有数, s用来存储数的位数,t是截取掉最高位之后的数 + for(i=1;i<9999;i++){ + t = i; + while(t > 0){ + s = (t/10==0?1:(t/100==0?2:(t/1000==0?3:4)));//求出这个数字位数 + t = i%(int)pow(10, s-1);//使用模除去掉最高位 + if(t*t == i){ + printf("%d:%d\n", t, i); + } + } + } + + + + return 0; +} ``` ### 循环结构-5