google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a program to add corresponding elements of two arrays - 2nd puc computer science

Write a program to add corresponding elements of two arrays

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                                                                              

11 
Write a program to add corresponding elements of two arrays Write a program to add corresponding elements of two arrays Reviewed by Vision Academy on December 12, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.