How can we make a function which can return an sum of two arrays i have tried it more than 10 times but it just print the sum of first elemts of both array upto m times pls help me
here is my code :
https://ide.codingblocks.com/s/53539
Sum of Two array
Hey Ankush, your approach is not correct, think the two arrays as 2 numbers and we have to add them.
For eg.
5
1 2 3 4 5
4
4 5 6 3
So, start adding the elements from last one by one as we do with two numbers in maths.
1 2 3 4 5
+ 4 5 6 3
= 1 6 9 0 8
Solve this problem with the approach of simply adding two numbers.
last carray is not added when i tried for(i = k) in line 16 in my code : https://ide.codingblocks.com/s/54192
Hey, you can check if carry exist at last then you can add it on kth position and start the print loop from k otherwise start the print loop from k-1.
int i=k-1;
if(carry){
c[k]=carry;
i=k;
}
for(;i>=0;i--){
cout<<c[i]<<", ";
}
cout<<"END";
you can refer this code snippet from your code.