var
count:string;
n,m,i,max:integer;
begin
count:=inttostr(n);
m:=length(count);
for i:= to m do
begin
max:=max+strtoint(count[i]);
end;
end;
我用delphi做的 ,思路其实是一样的 ,你改下语法就可以了 ,时间长不用C了
# include
void main()
{
int n,sum=0,digit=0;
scanf("%d",&n);
while(n!=0)
{
sum+=n%10;
digit++;
n/=10;
}
printf("每位和:%d\t位数:%d\n",sum,digit);
}