Add two Array data structure by R4R Team

Array:

Array is the collection of different values having same data type.
-We have a integer Array that having all integer values.
-Character array is known as String.

Addition of two Array:
Example-
Array1 is {1,2,3,4,5}
Array2 is {1,0,1,1,0}
//Addition is {2,2,4,5,5}

program-

#include < stdio.h>
int main()
{
int a[5],b[5],c[5],i;
printf("Enter 5 number in first array\n");
for(i=0;i< 5;i++)
scanf("%d",&a[i]);
printf("Enter 5 number in second array\n");
for(i=0;i< 5;i++)
scanf("%d",&b[i]);
// Now add both array
for(i=0;i< 5;i++)
{
c[i]=a[i]+b[i];
}
//Now traverse
printf("After addition\n");
for(i=0;i< 5;i++)
printf("%d,",c[i]);
}


output-

Enter 5 numbers in first array
1 2 3 4 5
Enter 5 number in second array
6 5 4 8 9
After addition
7,7,7,12,14

-In this program, we take a input of two Array.
-then we traverse both array and print the addition of each value.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!