Convert Int array to an integer

Is there anyway we can make an integer array to an integer

Thank you
Yes. Can you be more specific about what you wish to do?
Duoas


Of course

IF we have an integer array such as int A[3] = {1,2,3}

How do we make it int A = 123.

Thanks
Remember your basic math. This is kind of the opposite of logarithm -- each element is multiplied by a power of ten.

123 = 1×102 + 2×101 + 3×100

Another example:

7926 = 7×103 + 9×102 + 2×101 + 6×100

The simplest way for your array is an iterative approach:

1
2
3
4
result = 0
for each element in array, first to last:
  result *= 10
  result += element

Hope this helps.
Topic archived. No new replies allowed.