【函数】编写一个函数,显示求模运算的结果

该博客介绍编写一个求模运算程序,将用户输入的第一个整数作为求模运算符的第二个运算对象且保持不变,后续输入的数为第一个运算对象,输入非正值时程序结束,并给出了程序的输出示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

编写一个程序,显示求模运算的结果。把用户输入的第1个整数作为求模运算符的第2个运算对象,该数在运算过程中保持不变。用户后面输入的数是第1个运算对象。当用户输入一个非正值时,程序结束。其输出示例如下:

This program computes moduli.

Enter an integer to serve as the second operand: 256

Now enter the first operand: 438

438 % 256 is 182

Enter next number for first operand (<= 0 to quit): 1234567

1234567 % 256 is 135

Enter next number for first operand (<= 0 to quit): 0

Done
 

#include <stdio.h>
int main()
{
    int a, b;
    printf("This program computes moduli.\n");
    printf("Enter an integer to serve as the second operand: ");
    scanf("%d",&a);
    printf("Now enter the first operand: ");
    scanf("%d",&b);
    printf("%d / %d is %d",b,a,b%a);
    printf("\nEnter next number for the first operand: ");
    scanf("%d",&b);
    while(b>0)
    {
            printf("%d / %d is %d",b,a,b%a);
            printf("\nEnter next number for the first operand: ");
            scanf("%d",&b);
    }
    printf("Done");
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值