Тёмный

GO - Reverse a Number 

Подписаться
Просмотров 11
% 1

Given a number, we shall write a function that returns the reverse of the given number.
Take a variable to store the reversed number, say reversed. In a for loop, while n is not equal to zero, get the last digit of n by computing the remainder of the division of n by 10. Use modulus operator for this. Once we get this last digit, append this last digit to the reversed number. Appending is done by multiplying the existing value in output reversed variable with 10, and then adding the last digit of n.
Since we have used the last digit of n, we need to remove that last digit. Use division for this. Dividing n by 10, and reassigning the result back to n, results in the deleting of last digit from n.

Опубликовано:

 

29 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии