# Plz help...number string!!

• 11-23-2006
symbee
Plz help...number string!!
Hi all,

I have a number like 51634792 from which I want to fetch 1372. i.e other numbers are just for padding. How can I achieve this in C++? The number is Integer type.

Kindly help

Symbee
• 11-23-2006
Tonto
Well, you think about the math behind it, and we'll help you out with the C++ part.

Hint: think about what you could do to isolate a digit from that number.
• 11-23-2006
symbee
I have thought about devide and modulo method like if number is 12 then 12%10=2 and 12/10=1(only integer and not float) but I dont know about 8 digit number!! probably by resursion I can do! but as I m newbie, I dnt know how to achieve that

Kindly help

Best regards
Symbee
• 11-23-2006
Cat
Well, not recursion necessarily, but certainly a loop:

1234 % 10 = 4 <---
1234 / 10 = 123

123 % 10 = 3 <---
123 / 10 = 12

12 % 10 = 2 <---
12 / 10 = 1

1 % 10 = 1 <---
1 / 10 = 0

Note you can even continue the pattern, so you can program to extract enough digits to fit the largest possible ints, without a problem:

0 % 10 = 0
0 / 10 = 0
• 11-23-2006
Tonto
Recursion is a way of performing repetition, but there are also iterative 'loop' structures.

http://www.cplusplus.com/doc/tutorial/control.html

You got the gist of it. But try these operations on for size.

1 % 10 = 1;
1 / 10 = 0;
• 11-23-2006
symbee
Thanx all,

Regards
Symbee