Hi guys, i am looking for a function to fuse the elements of an array into a single "int" variable, to make it simple i am looking for the opposite of this function, couldn`t really figure it out
1 2 3 4 5
for(i = 9 ; i >= 0 ; i--)
{
array[i] = N%10;
N = N / 10;
}
If you don't want to use your brain, then why on earth are you trying to learn programming?
When you have the digits 1, 2 and 3, how do you get to 123? This is first grade maths.
and i wonder where did you got that 0*10 from ?
What value does a have? What happens when you multiply it by 10? Or even better, if a is 0 after you multiplied the previous value by 10, what was the previous value?
I say stop trying to figure out how to "invert" that function and just write the calculation. If int digits[5]; holds the digits of a 5 digit number then the N you are looking for is: int N = digits[0] + 10*digits[1] + 100*digits[2] + ...
Just put that in a loop.
@Athar: Hope you don't mind me stepping in here.
Question for you. The meaning of big-endian vs. little-endian in a number representation.
I have chosen big-endian above because I am storing the most significant digit last, correct?
The endianness is named for what is in element 0 then, not the last element?
I store the least significant digit (the little one) in digits[0], so it is little-endian?
I see, by refering to OP's OP (original post), that he is indeed assigning the ones digit to array[9] on the 1st iteration, so it would be big-endian.
I was confused because I thought the "end" in "endian" referred the "end" of the array, not the beginning.
i wanted to point at the fact that "&a" is the address in which the 12345 number has to be stored, but no matter how hard i tried it kept outputing "0"