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
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
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.
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
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
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.
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;
Thanx all,
Regards
Symbee