Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C++ Example - Quotient and Remainder

C++ Example - Quotient and Remainder

C++ Example C++ Example

Use C++ to get two numbers from the user, divide them, and output the quotient and remainder to the screen:

Example

include

<

iostream

using

namespace

std

;

int

main

(

)

{

int

divisor

,

dividend

,

quotient

,

remainder

;

cout

<<

"

Enter the dividend:

"

;

cin

dividend

;

cout

<<

"

Enter the divisor:

"

;

cin

divisor

;

quotient

=

dividend

/

divisor

;

remainder

=

dividend

%

divisor

;

cout

<<

"

Quotient =

"

<<

quotient

<<

endl

;

cout

<<

"

Remainder =

"

<<

remainder

;

return

0

;

}

The output of the above program is:



输入被除数: 13

输入除数: 4

商 = 3

余数 = 1

C++ Example C++ Example