Write a program to add corresponding elements of two arrays
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],b[10],sum[10],n,i;
clrscr();
printf("How many elements in each array? ");
scanf("%d",&n);
printf("Enter the elements of array A\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the elements of array B\n");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
sum[i]=a[i]+b[i];
printf("Sum of elements of A and B are\n");
for(i=0;i<n;i++)
printf("%d\n",sum[i]);
getch();
}
Output:
How many elements in each array? 3
Enter the elements of array A
1
3
5
Enter the elements of array B
2
4
6
Sum of elements of A and B are
3
7
No comments: