Monday, June 18, 2012

To find the sum of the corresponding elements of two 1-D arrays


/* Program to find the sum of the corresponding elements of two 1-D arrays */

#include<stdio.h>

#include<conio.h>

void main()

{

  int a[10],b[10],sum[10],i;

  clrscr();

  /* To enter elements in a 1-D array */

  printf("Enter the elements of first array:\n");

  for(i=0;i<10;i++)

  {

    scanf("%d",&a[i]);

  }

  printf("Enter the elements of second array:\n");

  for(i=0;i<10;i++)

  {

    scanf("%d",&b[i]);

  }

  /* Sum of two arrays */

  for(i=0;i<10;i++)

  {

    sum[i] = a[i] + b[i];

  }

  printf("\nSum of elements of first and second array:\n");

  for(i=0;i<10;i++)

  {

    printf("\t%d",sum[i]);

  }

  getch();

}

 

OUTPUT

Enter the elements of first array:

1

2

3

4

3

2

5

1

6

3

Enter the elements of second array:

5

3

2

6

1

2

5

4

3

2

 

Sum of elements of first and second array:

        6       5       5       10      4       4       10      5       9                  5

 
 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.