# Thread: Recognizing each digit of an integer

1. ## Recognizing each digit of an integer

Hi! I was wondering if there was a more effective way to recognize each digit of a given integer. Given an integer called name, this is what I got.

Code:
```    float name, a;
name= 4734;
a=name;

for(int i=0; i< f; i++)
{
x=1+log10(a);
y=a/pow(10, x-1);
digits[i]=y;
a-=y*pow(10, x-1);
cout << "digits= " << digits[i] << endl;
}```
Ohh and I was wondering if there any good sites to learn recursion. Thanks!!

2. Isn't this in the FAQ?

Lets take the cheat way
Code:
```float somenum = 123452f;
std::string digits;
ostringstream oss;
digits = oss.str();```
now you can use digits as an array of char with each containing a number. (Possible problem if the number actually has a decimal point in it)

Note: Untested code, some mistake may appear. Finding them is left as an excersice for the user.

3. Hi! I was wondering if there was a more effective way to recognize each digit of a given integer. Given an integer called name
Code:
`float name`
??
Possible problem if the number actually has a decimal point in it)
??

4. Maf-o-matics

With modulus and division:

123456 % 100 = 56 Correct?
56 / 10 = 5 Correct?

113355 % 10000 = 3355 Correct?
3355 / 1000 = 3 Correct?

See how it works?