#include
#define N 5
int main(void){
int x,y= 0,z;
int sum[N] ={0} ;
int s = 0 ;
int code;
printf("请输入一个整数( 小于或等于32767): ");
scanf("%d",&x);
do {
code = x % 10 ;
sum[y] = code ;
x = x/10 ;
++y ;
if ( 0 == x){
break ;
}
}
while (y <=4) ;
for( z= 0 ; z < N;z++){
s = s+sum[z] ;
}
printf("总值: %d",s);
return 0 ;
}
#include
void main()
{
int a,b[10],i,j,sum;
scanf("%d",&a);
for(i=0;a;i++){
b[i]=a%10;
a=a/10;
}
if(!i) printf("sum=0\n");
for(j=0,sum=0;j sum+=b[j];
printf("sum=%d\n",sum);
}