I did in java, here I take the numbers N1 and N2, and I created an array of size 1000. Let's take an example How to solve this, N1 = 12, N2 = 1234. For N1 = 12, temp = N1% 10 = 2. Now add this digit with the digit N2 from right to left and save the result in an array, starting with i = 0, similarly for the resting digit N1. The array will save the result, but in reverse order. Take a look at this link. Check out this link http://ideone.com/V5knEd
import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone
{
public static void main (String[] args) throws java.lang.Exception {
Scanner scan=new Scanner(System.in);
int A=scan.nextInt();
int B=scan.nextInt();
int [] array=new int[1000];
Arrays.fill(array,0);
int size=add(A,B,array);
for(int i=size-1;i>=0;i--){
System.out.print(array[i]);
}
}
public static int add(int A, int B, int [] array){
int carry=0;
int i=0;
while(A>0 || B>0){
int sum=A%10+B%10+carry+array[i];
array[i]=sum%10;
carry=sum/10;
A=A/10;
B=B/10;
i++;
}
while(carry>0){
array[i]=array[i]+carry%10;
carry=carry/10;
i++;
}
return i;
}
}
geeks source
share