-
May 4th, 2007, 01:01 AM
#1
Thread Starter
Hyperactive Member
Converting a double digit to single digit
how do you convert a double digit number, to a single digit in C
say, if you have 34 i want it to convert to,
3*10 + 4 does anyone know of a ready-made algo (or code)?
cheers!
-
May 4th, 2007, 04:30 AM
#2
Re: Converting a double digit to single digit
Why do you want to convert it to the algorithm? That ain't exactly a single digit as you stated in your threads title.
-
May 5th, 2007, 06:36 AM
#3
transcendental analytic
Re: Converting a double digit to single digit
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 6th, 2007, 01:13 AM
#4
Junior Member
Re: Converting a double digit to single digit
Kedaman that link just shows how to double the integer though.
-
May 6th, 2007, 02:53 AM
#5
transcendental analytic
Re: Converting a double digit to single digit
Originally Posted by vbleet
Kedaman that link just shows how to double the integer though.
Well the example shows how to do that, but thats not the point. I guessed he was asking for how to convert a string of digits to an integer.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 7th, 2007, 12:32 AM
#6
Re: Converting a double digit to single digit
Originally Posted by deane034
how do you convert a double digit number, to a single digit in C
say, if you have 34 i want it to convert to,
3*10 + 4 does anyone know of a ready-made algo (or code)?
cheers!
You would need to first convert it into a string, then append the multiplication factor to each digit (char) in the string. The simplest way would involve converting each char back into an integer. There's probably some mathematical way of avoiding the second conversion, but I can't think of it right now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|