Addition of two arrays

Addition of two arrays :

main()
{
int a[50],b[50],i,n,c[50];

printf("\n Enter the number of elements : ");
scanf("%d",&n);

printf("\nEnter the elements of array a - ");
for(i=0; 
i < n; i++)
{
  scanf("%d",&a[i]);
}

printf("\nEnter the elements  of array b - ");

for(i=0; i < n; i++)
{
  scanf("%d",&b[i]);
}


printf("\nAddition of two array are   \n ");
for(i=0; 
i < n; i++)
{

  c[i] = a[i] + b[i];
  printf("\n %d x %d = %d",a[i],b[i],c[i]);
}


}

Initially three arrays namely a,b,c are declared with maximum size of 50 integer elements, looping variable i and n is also declared. Then accept the number of values you want to feed. In first and second loop inputting the values for array a and b respectively. Third loop is used for adding every element of array a and b storing the result into corresponding position of array c.





Comments