numbers)
Data Structures and Algorithms
In this lecture we will learn about two mathematical concepts - divide and percent sign, and how they
can be used to find the reverse of a number. To do this, we first need to divide the number by 10 and
then reverse the result. For example, if we divide 5 by 10, we get 0.5. To reverse this, we again divide 0.5
by 10, which gives us 5. Therefore, the reverse of 5 is 0.5 and the reverse of 5.00 is 5.
Now, let us understand how to use this concept to reverse a given number. We need to create a variable
called "reverse" and initialize it to 0. Then, for each digit of the given number, we add it to the "reverse"
variable and multiply "reverse" by 10. For instance, if we have the number 34, we start with "reverse" as
0. Then, we add 3 to it, which becomes 3. Next, we multiply "reverse" by 10, so it becomes 30. Finally,
we add 4 to it, so the "reverse" variable becomes 34.
To apply this concept in code, we can declare a variable "time" equal to the input number. Then, we
declare another variable "reverse" and initialize it to 0. For each digit in "time", we add it to "reverse"
and multiply "reverse" by 10. Finally, we return the "reverse" variable as the reversed number.
Understanding divide and percent sign is essential for manipulating numbers and performing
mathematical operations effectively.
Let us break down the concepts and add some examples to make it clearer.
Divide and percent sign:
The divide sign is represented by ÷ and is used to divide one number by another.
The percent sign is represented by % and is used to represent a part of a whole. For example, 25%
represents 25 parts out of 100.
Reverse of a number:
The reverse of a number is the number obtained by writing its digits in the opposite order. For example,
the reverse of 1234 is 4321.
Now let us move on to the example given in the video:
The task is to find the reverse of a number.
To do this, we need to add each digit of the number to a new variable called "reverse" while multiplying
"reverse" by 10 each time.
For example, if the number is 34, we first add 4 to "reverse" and make it 4. Then we multiply "reverse"
by 10 and add 3 to it to get 43, which is the reverse of 34.
Here is another example: