U
U
Username2015-07-15 22:33:11
Programming
Username, 2015-07-15 22:33:11

How to convert int array to int?

There is an array of integers, how to get one unique from all these numbers?

int myints[] = {7, 4, 5, 3, 0};
int a;
//Хочу чтобы a = 74530;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2015-07-15
@dalv_happy

Okay, all you need to do is think a little.
A simple option (just for int): loop from the "end" of the array, multiplying the number each time. That is, 0 * 1 + 3 * 10 + 5 * 100 + 4 * 1000 + 7 * 10000.
And if the numbers are as a string (for example, you can enter them in a loop), adding everything as a string (or transfer the number to a string and add it. But you shouldn't do this, it's just an example of the fact that there are always several ways).

D
d0002, 2015-07-15
@d0002

for(int i=4;i>=0;i--)a=myints[i]+a*10;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question