Sum of 2 arrays using Functions
Problem Description
Write a program to find the sum of the corresponding elements in 2 arrays.
Input Format:
Input consists of 2n+1 integers. The first integer corresponds to n , the size of the array. The next n integers correspond to the elements in the first array. The last n integers correspond to the elements in the second array. Assume that the maximum value of n is 15.
Output Format:
Refer sample output for details
CODING ARENA
#include <stdio.h>
int main()
{
int n,a[100],b[100],i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
printf("%d ",a[i]+b[i]);
return 0;
}
Test Case 1
Input (stdin)5
2 3 6 8 2
1 1 1 1 1
Expected Output
3 4 7 9 3
Test Case 2
Input (stdin)3
0 9 8
1 2 3
Expected Output
1 11 11
No comments:
Post a Comment