|
From: Purohit P. J.. <pra...@si...> - 2001-04-20 07:03:39
|
Hello,
To use a number backward first you need to separare the digits of =
the no.
To do this say you have nNo=3D5234
To separate thousands digit ie 5 thousnad_digit =3D nNo/1000;
To get the hundred digit ie 2 hunreds_digit =3D =
(nNo%1000)/100;
( In above nNo%1000 will give 234 and then 234/100 will give =
2 )
To get tens digit ie 3 tens_digit =3D =
(nNo%100)/10;
( In above nNo%100 will give 34 and then 34/10 will give 3 )
To get the units digit ie 4 unit_digit =3D (nNo%10);
( In Above nNo%10 Will give 4 )
% is Called MODULUS OPERATOR and it give remainder of a =
division.
Now you have separated all the digits of original no now to revert =
the no. simply change the units digit to thousands digit,
tens digit to hundreds digit, hundreds digit to tens digit, thousands =
digit to unit digit. The nos get reversed.
=20
RevNo =3D unit_digit*1000 + tens_digit*100 + hundreds_digit*10 + =
thousand_digit ;
=20
( This above expression is equal to RevNo =3D 4*1000 + 3*100 =
+ 2*10 + 5 ; therefore RevNo=3D4325 )
Haha we reversed the no.
Bye.,
Prahlad Purohit
----- Original Message -----=20
From: "Lorenzo" <co...@in...>
To: <dev...@li...>
Sent: Thursday, April 19, 2001 5:21 PM
Subject: Re: [Dev-C++] Number backwards?
>=20
>=20
> > 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.
>=20
> WHY?
> Though you can convert int to string with itoa and use the strrev to =
invert
> order of character and convert string to int with atoi.
>=20
>=20
>=20
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|