安全问答

安全问答是一个知识全球问答,包含丰富的问答知识

首页 常规 游戏 娱乐 科技

C语言实现各位数求和函数

  • 日期: 2028-07-05 21:56:11
  • 标签: 常规
#include <stdio.h>

int sum(int i) {
    int res = 0;
    while (i > 0) {
        res += i % 10;
        i /= 10;
    }
    return res;
}

int main() {
    int n, num;
    scanf('%d', &n);
    for (int i = 0; i < n; i++) {
        scanf('%d', &num);
        printf('%d\n', sum(num));
    }
    return 0;
}

原文地址: https://www.cveoy.top/t/topic/oZ0k 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录

  • 上一篇: Heat Transfer Rate Calculation for Finned Tube in Commercial Building Heating System
  • 下一篇: 李镇西:给教师的36条金玉良言,提升教学水平,成就学生未来

© 2019 • 2025 - 安全问答 站长邮箱:wxgpt@qq.com    ICP备案/许可证号:豫ICP备2024104334号-2