如题所述
#include<stdio.h>
int main()
{int n,s=0;
scanf("%d",&n);
while(n>0)
{printf("%d",n%10);
s+=n%10;
n/=10;
}
printf("\n各位之和=%d\n",s);
return 0;
}
int main()
{int n,s=0;
scanf("%d",&n);
while(n>0)
{printf("%d",n%10);
s+=n%10;
n/=10;
}
printf("\n各位之和=%d\n",s);
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 2018-01-23
先写出其倒序,然后求其和。
具体程序代码如下:
#include "stdio.h"
int main ()
{
int x,y; //x是原数字,y是倒序后的数字
printf("请输入原数字:");
scanf("%d",&x) ;
if(x>9999) printf("输入数字不能超过9999");
else
{
for(y=0;x!=0;x=x/10 )
y=y*10+x%10;
}
printf("倒序后的数字是:%d",y);
system("pause");
}
本回答被网友采纳