⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 digitsum.c

📁 书名:C语言科学与艺术,以前交钱下载的
💻 C
字号:
/* * 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -