C Language Examples - Divide Two Numbers
Divide two numbers; if there is a remainder, output it.
Example
#include
<
stdio.h
int
main
(
)
{
int
dividend
,
divisor
,
quotient
,
remainder;
printf
(
"
Enter the dividend:
"
)
;
scanf
(
"
%d
"
, &
dividend
)
;
printf
(
"
Enter the divisor:
"
)
;
scanf
(
"
%d
"
, &
divisor
)
;
// Calculate the quotient
quotient
=
dividend
/
divisor
;
// Calculate the remainder
remainder
=
dividend
%
divisor
;
printf
(
"
Quotient = %d
\
n
"
,
quotient
)
;
printf
(
"
Remainder = %d
"
,
remainder
)
;
return
0
;
}
Running result:
输入被除数: 5
输入除数: 2
商 = 2
余数 = 1
C Language Examples