i have to convert an array of integers into number. for the given code if a test case is taken as 1 0 7 6 2 for an array of 5 numbers output is 10761

#include<stdio.h>
#include<math.h>
int main()
{
int t,n,k,i;
int sum;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sum=0;
k=n-1;
for(i=0;i<n;i++)
{
sum=sum+(a[k]*pow(10,i));
k–;
}
printf("%d\n",sum);
return 0;
}

Just don’t use the pow function if your result will not be a floating type. In this case is recommended to write your own function (or in this case to use another variable, let’s say power, which is multiplied by 10 every loop).

Hello destiny_me ,

You can achieve using this way …

 int num = 0 ;
 for(int i=0;i<n;i++){
      num = num * 10 + arr[i] ;
 }
 cout << num << endl ;

Here is the recursive way for the same:

int find_num(int a[], int start, int n, int num)
{
if(start==n)
 return num;
 
num= num*10 + a[start];
return find_num(a,start+1,n,num);
}

with the call : cout<<find_num(a,0,n,0); // a is the input array and n is total number in the array and start refers to the starting index i.e. 0 and num, is the number formed at some particular step.

you can just use StringBuilder or StringBuffer and append every number of array and last you can convert string into number by parsing it…