diff --git a/2207/C语言同步练习源码/2.循环结构-5.c b/2207/C语言同步练习源码/2.循环结构-5.c new file mode 100644 index 0000000..ea32b9e --- /dev/null +++ b/2207/C语言同步练习源码/2.循环结构-5.c @@ -0,0 +1,31 @@ +#include + +int main(){ +/* + int x, n, t=1;//tΪ2ǰҪλ + + scanf("%d", &x); + n = x;//֮ + while(t < x){//жλǷ񳬹ķΧ + n+=t*2; + //ݵǰλжǰһλǷһ + if(n/(t*10) != x/(t*10)){ + n-=(t*10); + } + t*=10;//һλ + } + printf("%d:%d\n", x, n); +*/ + int x, s = 0; + scanf("%d", &x); + while(x){ + s*=10; + s += (x%10+2)%10; + x /= 10; + } + for(;s;s/=10){ + printf("%d", s%10); + } + + return 0; +} diff --git a/2207/C语言同步练习答案.md b/2207/C语言同步练习答案.md index 0435360..d5f5b49 100644 --- a/2207/C语言同步练习答案.md +++ b/2207/C语言同步练习答案.md @@ -280,6 +280,37 @@ int main(){ ![image-20250220231006104](https://yp.smallkun.cn/markdown/image-20250220231006104.png!compress) ```c +#include + +int main(){ +/* + int x, n, t=1;//t为2当前需要加入的位置 + + scanf("%d", &x); + n = x;//处理之后数 + while(t < x){//判断位置是否超过的数的范围 + n+=t*2; + //根据当前输入位置判断前一位是否溢出如果溢出则减一 + if(n/(t*10) != x/(t*10)){ + n-=(t*10); + } + t*=10;//继续处理下一位 + } + printf("%d:%d\n", x, n); +*/ + int x, s = 0; + scanf("%d", &x); + while(x){ + s*=10; + s += (x%10+2)%10; + x /= 10; + } + for(;s;s/=10){ + printf("%d", s%10); + } + + return 0; +} ``` ### 循环结构-6