C 语言实例 – 两数相除

C语言教程评论

C 语言实例 - 两数相除

两数相除,如果有余数,输出余数。

#include <stdio.h>


int main(){


    int dividend, divisor, quotient, remainder;


    printf("输入被除数: ");
    scanf("%d", &dividend);


    printf("输入除数: ");
    scanf("%d", &divisor);


    // 计算商
    quotient = dividend / divisor;


    // 计算余数
    remainder = dividend % divisor;


    printf("商 = %d\n", quotient);
    printf("余数 = %d", remainder);


    return 0;
}

运行结果:文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-liangshuxiangchu.html

输入被除数: 5
输入除数: 2
商 = 2
余数 = 1
文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-liangshuxiangchu.html文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-liangshuxiangchu.html
运营不易,
感谢支持!
weinxin
我的微信
我的微信公众号
我的微信公众号扫一扫
weinxin
我的公众号
 最后更新:2021-12-7
公式库网
  • 本文由 公式库网 发表于 2021年12月4日22:04:20
  • 转载请务必保留本文链接:https://www.gongshiku.com/html/202112/c-yuyanshili-liangshuxiangchu.html

发表评论