C 语言程序查找商和余数

编写一个C语言程序来查找商和余数。本示例允许用户输入两个整数值,并使用/和%运算符来计算商和余数。

#include <stdio.h>

int main()
{
    int number1, number2;
    float quotient, remainder;
    
    printf("Enter the Number to perform Division = ");
    scanf("%d",&number1);

    printf("Enter the Divisor Number = ");
    scanf("%d",&number2);
    
    quotient = number1 / number2;

    remainder = number1 % number2;

    printf("The Quotient of %d and %d   = %.2f", number1, number2, quotient); 
    printf("\nThe Remainder of %d and %d = %.2f\n", number1, number2, remainder);
}
Program to Find Quotient and Remainder

在此程序中,两个用户定义的函数接受两个整数值,并找到商和余数。

#include <stdio.h>

float calcQuot(int a, int b) {
    return a / b;
}

float calcRem(int a, int b) {
    return a % b;
}

int main()
{
    int num1, num2;
    float quot, rem;
    
    printf("Enter the Number = ");
    scanf("%d",&number1);

    printf("Enter the Divisor Number = ");
    scanf("%d",&number2);
    
    quot = calcQuot(num1, num2);

    rem = calcRem(num1, num2);

    printf("The Quotient of %d and %d = %.2f\n", num1, num2, quot); 
    printf("The Remainder of %d and %d = %.2f\n", num1, num2, rem);
    
    return 0;
}
Enter the Number = 229
Enter the Divisor Number = 5
The Quotient of 229 and 5 = 45.00
The Remainder of 229 and 5 = 4.00