#include<stdio.h>void main(){ int a,b,c,d,e,f,g,h,sum; scanf("%d",&a); if(a>=1000&&a<=9999) { b=a/1000; c=a%10; d=a/1000; e=a/100; f=e%10; g=a/10; h=g%10; sum=c*1000+f*10+h*100+d; printf("转换后:%d",sum); } else printf("此数不为4位数");}
呃,我有更简单的算法,直接利用函数递归调用#include<stdio.h>voidfoo(void){ charch; if((ch=getchar())!='\n') foo(); putchar(ch); }intmain(){ foo(); printf("\n"); return0;}