Hello I am writing a fuction to return a number's digit in a spcific plance.
Number : 12345
Place:1 = 5
Place:2 = 4
.
.
.
here is what I have:
Please helpCode:int get_digit(info& structure,int digit) { int ret_dig; ret_dig = structure.d_pop; }
Hello I am writing a fuction to return a number's digit in a spcific plance.
Number : 12345
Place:1 = 5
Place:2 = 4
.
.
.
here is what I have:
Please helpCode:int get_digit(info& structure,int digit) { int ret_dig; ret_dig = structure.d_pop; }
Use % and / on a temproary copy of the variable.
How Would I do this....could you please give me an example?
12345 % 10 = 5.
(12345 / 10) % 10 = 4.
(12345 / 10 / 10) % 10 = 3.
... etc.
% means mod, or remainder (12345 / 10 is 1234 remainder 5, so 12345 % 10 = 5).
Or convert it to a string and then just use normal array-like indexing [] and some math to get the proper digit.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
Thank You Very Much
I think you can write a recursive function for this purpose..
http://www.cprogramming.com/tutorial/lesson16.html