|
From: Bolek V. <vr...@pa...> - 2001-04-19 11:47:01
|
> How do I do if I want to use a number backwards?
> For example: If I give the variable 'n' the number 12345
> and want to use it as 54321. In cout for example.
unsigned backwards( unsigned n)
// Reverse order of digits (in decadic)
{
unsigned result = 0;
while (n > 0) {
result = 10*result + n % 10;
n = n / 10;
}
return result;
}
--
============================================================
Ing. Boleslav Vrany
Stanice techniku DDM hl. m. Prahy
Pod Juliskou 2a
Praha 6 - Dejvice
16000
Czech Republic
tel. (420 2) 243 10 240
|