Sum of Two Arrays

Please help me find the errors in this code. The output is coming out to be same as arr1.

using namespace std;

void sum(int arr1[],int arr2[],int N,int M){
int temp[1001];
int i = N-1, j = M-1, k = N-1;

int carry = 0; 
int s = 0;
while (j >= 0){
	s = arr1[i] + arr2[j] + carry;
	temp[k] = s%10;
	carry = s/10;
	j--;
	i--;
	k--;
}

while (i >= 0){
	s = arr1[i] + carry;
	temp[k] = s%10;
	carry = s/10;
	i--;
	k--;
}

int ans = 0;
if (carry){
	ans = 10;
}
for (int p = 0; p < N; p++){
	cout << temp[p] << ", ";
}

cout << "END" << endl;

}
void calSum(int arr1[],int arr2[],int N,int M){
if (N>=M){
return sum(arr1, arr2, N, M);
}
else
return sum(arr2, arr1, M, N);
}
int main() {
int N;
int arr1[1000];
for (int i = 0; i < N; i++){
cin >> arr1[i];
}

int M;
int arr2[1000];
cin >> M;
for (int i = 0; i < M; i++){
	cin >> arr2[i];
}
calSum(arr1, arr2, N, M);
return 0;

}

Please save your code on ide.codingblocks.com and then share its link.

In line 44, you have initialized n…but you have not taken its input.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.