digitsum.c
来自「The art and science of c_source code!」· C语言 代码 · 共 28 行
C
28 行
/* * File: digitsum.c * ---------------- * This program sums the digits in a positive integer. * The program depends on the fact that the last digit of * a integer n is given by n % 10 and the number consisting * of all but the last digit is given by the expression n / 10. */#include <stdio.h>#include "genlib.h"#include "simpio.h"main(){ int n, dsum; printf("This program sums the digits in an integer.\n"); printf("Enter a positive integer: "); n = GetInteger(); dsum = 0; while (n > 0) { dsum += n % 10; n /= 10; } printf("The sum of the digits is %d\n", dsum);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?