Page 145 - Cs_withBlue_J_C11_Flipbook
P. 145

The table given below shows the binary arithmetic operators which deal with two operands:

                         Operator       Meaning                        Description                     Example

                             +      Addition         It is used to find the sum of the values of the two operands. a + b
                             -      Subtraction      It is used to find the difference of the values of the two  a - b
                                                     operands.
                             *      Multiplication   It is used to find the product of the two operands.  a * b

                             /      Division         It is used to find the quotient of the two operands.  a / b

                             %      Modulus          It is used to find the remainder of the two operands.  a % b

                 The following program demonstrates the use of binary arithmetic operators:


























                 The output of the preceding program is given below:

                 Enter 1st number: 4
                 Enter 2nd number: 3
                 Sum: 7
                 Product: 12
                 Difference: 1
                 Quotient: 1.3333333333333333
                 Remainder: 1
                 The table given below shows the unary arithmetic operators which deal with one operand:

                             Operator          Meaning          Description         Usage            Example

                         Unary +           Unary Plus        It returns the same   Used before the   double val=45.76;
                                                             value.            operand.
                                                                                                 then +val will be
                                                             The value of the                    +45.76 which is
                                                             operand remains                     same as 45.76.
                                                             the same.
                         Unary -           Unary Minus       It returns the value   Used before the   double val=-45.76;
                                                             with the reversed   operand.        then -val will be
                                                             sign.
                                                                                                 45.76 as -(-45.76) is
                                                                                                 45.76.

                                                                                                                       143
                                                                                               Variables and Expressions  143
   140   141   142   143   144   145   146   147   148   149   150