C语言程序计算整数各位数字之和

 时间:2026-02-14 17:43:37

1、ubuntu 14.04 linux c

gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2

2、#include<stdio.h>

#include<stdlib.h>

int main()

{

        char integer[100];

        int value = 0,temp_value = 0,sum = 0;

        gets(integer);

        value = atoi(integer);

        temp_value = value;

        while(value >= 1)

        {

                sum += value%10;

                value = value / 10;

        }

        printf("the integer is %d and the sum of decimal digits is %d \n",temp_value,sum);

        return 0;

}

3、xxx@linux:~/code$ gcc -o sum sum.c 

xxx@linux:~/code$ ./sum 

123

the integer is 123 and the sum of decimal digits is 6 

xxx@linux:~/code$ ./sum

12345

the integer is 12345 and the sum of decimal digits is 15

  • z=xy的图像怎么画
  • C语言逆序输出
  • 如何绘制校准曲线
  • 点到平面的投影怎么算
  • z=x^2+y^2图像怎么画
  • 热门搜索
    裤子粘毛怎么办 途乐怎么样 董明珠简介 皇后成长计划2攻略 熹妃传厨房攻略 腾达无线路由器怎么设置 萧军简介 外阴白斑是怎么回事 重庆美食攻略 中药减肥茶