// 数据分离和逆序输出.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "stdio.h" #include "stdlib.h" int Getwei(int num) { // 12345 /10 1234 /10 123 10 /12 /10 1 /10 0 int wei=0; for (;num;num/=10) { wei++; } return wei; } int get10N(int num) { // num=3 int res=1; for (int i=0;i<num;i++) { res=res*10; } return res; } int nixu(int num,int wei) { int last=0; for (int i=0;i<wei;i++) { int shu=0; shu=num%10; num/=10; last+=shu*get10N(wei-1-i); printf("shu=%d,i=%d,wei-1-i=%d,last=%d\n",shu,i,wei-1-i,last); } return last; } void main() {//12345 10000 2000 300 40 5 int num; scanf("%d",&num); printf("原始num=%d\n",num); int wei=Getwei(num); printf("wei=%d\n",wei); int res=get10N(wei); int last=0; last=nixu(num,wei); printf("last=%d\n",last); system("pause"); }