In this program, we will create and initialize two integer arrays then add both array elements and assign them to another array. After that, we will print elements of all arrays on the console screen.
In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt package that includes the files of package fmt then we can use a function related to the fmt package.
In the main() function, we created and initialized two arrays arr1, arr2 and also declared one another array arr3.
// Add two arrays
for i:=0;i<=4;i++{
arr3[i]=arr1[i] +arr2[i]
}
In the above code, we added the elements of arrays arr1 and arr2 and assigned them to the arr3. After that, we printed the elements of all arrays on the console screen.
Program/Source Code:
The source code to add two integer arrays is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt package that includes the files of package fmt then we can use a function related to the fmt package.
In the main() function, we created and initialized two arrays arr1, arr2 and also declared one another array arr3.
In the above code, we added the elements of arrays arr1 and arr2 and assigned them to the arr3. After that, we printed the elements of all arrays on the console screen.