Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Lập Trình C

Chương trình C tính thương và dư

Cho số bị chia (dividend) và số chia (divisor), tính thương (quotient) và dư (remainder).

Công thức: quotient = dividend / divisor, remainder = dividend % divisor.

Ví dụ

Input: Dividend=6, Divisor=2
Output: Quotient=3, Remainder=0

Chương trình C ví dụ

#include <stdio.h>
int main() {
    int dividend=2, divisor=6, quotient, remainder;
    quotient = dividend / divisor;
    remainder = dividend % divisor;
    printf("Quotient=%d\nRemainder=%d", quotient, remainder);
    return 0;
}