用C语言程序编写“输入一个四位整数(如1234),使其倒序输出(如4321),并求其各位之和。”

如题所述

#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; 
}

温馨提示:答案为网友推荐,仅供参考
第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");

}

本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网