安全问答

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

首页 常规 游戏 娱乐 科技 程序员

c语言编写程序编写一个函数sumi将输入的整形参数ii0的各位求和返回求和结果。在main函数中测试此函数从键盘输入整数nn∈120然后再输入n个非负整数对于每一个非负整数调用sum函数求各位数和将结果输出到屏幕。

  • 日期: 2025-08-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;
}
c语言编写程序编写一个函数sumi将输入的整形参数ii0的各位求和返回求和结果。在main函数中测试此函数从键盘输入整数nn∈120然后再输入n个非负整数对于每一个非负整数调用sum函数求各位数和将结果输出到屏幕。

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

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

  • 上一篇: In commercial building heating systems hot water is often passed through radiators to heat the air in rooms To enhance the air-side heat transfer in the radiators annular fins of a rectangular profil
  • 下一篇: 李镇西给教师的36条建议

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