Computer Science, asked by vanshitab4231, 28 days ago

write a program to accept a 2 digit number display sum of that number number is 53 output 8 arthemetic operators % and //

Answers

Answered by Equestriadash
14

The following co‎des have been written using Python.

\tt n\ =\ int(in put("Enter\ a\ two-digit\ number: "))\\if\ n\ >=\ 10\ and\ n\ <=\ 99:\\{\ \ \ \ \ }s\ =\ n//10\ +\ n\%10\\{\ \ \ \ \ }print(s)\\else:\\{\ \ \ \ \ }print("Invalid\ number.")

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 (%).

>>>\ \tt4\%2\\0\\>>>\ 5\%2\\1

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 (//).

>>>\ \tt 4//2\\2\\>>>\ 5//2\\2

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.

Similar questions