#include "stdio.h"
int main(int argc,char *argv[]){
int n,s,t;
printf("Please enter n(int 999<n<10000)...\nn=");
if(scanf("%d",&n)!=1 || n<1000 || n>9999){
printf("Input error, exit...\n");
return 0;
}
for(s=0;n;n/=10){
printf("%d ",t=n%10);
s+=t;
}
printf("\nThe sum of them is %d\n",s);
return 0;
}
运行样例: