write a program to accept a 2 digit number display sum of that number number is 53 output 8 arthemetic operators % and //
Answers
The following codes have been written using Python.
Once the number has been entered, we use a conditional statement to check if the number is a two-digit number or not. If it isn't, an appropriate error message will be printed. Once it surpasses the two-digit number check, we perform the addition of the digits, as per the question, using the modulus (%) and floor/integer (//) division operators. The modulus operator is generally used to obtain the remainder of the division, while the floor/integer division operator is generally used to obtain the quotient of the division.
Examples to demonstrate the workings of both operators:
1. Using the modulus operators (%).
When 4 is divided by 2, the remainder is 0. When 5 is divided by 2, the remainder is 1.
Similarly, when the number entered is divided by 10, the remainder will be the units' place digit [the modulus and floor division operators do not take in decimal values and only extract the integer part], thereby obtaining one of the digits for the addition.
2. Using the floor/integer division operator (//).
When 4 is divided by 2, the quotient is 2. When 5 is divided by 2, the quotient is 2.5, but as mentioned above, since it takes only the integer part, the quotient, in this case, would be 2.
Similarly, when the number entered is divided by 10, the quotient will be the tens' place digit, thereby obtaining the second digit for the addition.