If the size of the array can be bigger you have to understand that a 32 bit integer is good for only nine decimal digits - log10(232), and that even a 64 bit integer is good for 19 decimal digits - log10(264). Either way, even your small example will not fit in a 32 bit int
.
Also there is no real mathematical purpose or relationship in appending arbitrary integers in this way, especially as each has a variable number of decimal significant digits - any algorithm would have to take that into account.
So for the reasons given, attempting to solve the problem arithmetically is both over complex and inflexible; the simpler solution is to generate the result as a string.
int A[]={156,23,212,4,12};
int i = 0 ;
int index = 0 ;
const int length_A = sizeof(A) / sizeof(*A) ;
char astr[length_A * 10 ] ; // sized to accommodate worst case
// string length for 32 bit int of INT_MAX.
for( i = 0; i < length_A; i++ )
{
index += sprintf( &astr[index], "%d", A[i] ) ;
}
printf( "%s", astr ) ;
If you really need an arithmetic solution and can work within the limits of the available integer data types, then I suggest that you use unsigned long long
for the output and unsigned int
for the input, then:
#include <stdio.h>
#include <math.h>
int main()
{
unsigned int A[]={156,23,212,4,12};
unsigned long long result = 0 ;
int i = 0 ;
const int length_A = sizeof(A) / sizeof(*A) ;
for( i = 0; i < length_A; i++ )
{
result += A[i] ;
if( i < length_A - 1)
{
int digits = (int)ceil( log10( (double)A[i+1] ) ) ;
result *= (int)pow( 10, digits ) ;
}
}
printf( "%llu\n", result ) ;
return 0 ;
}