Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a programmer defined function to add the elements of two arrays of 5 integ

ID: 3810953 • Letter: W

Question

Write a programmer defined function to add the elements of two arrays of 5 integers each. Your main function should declare three integer arrays-two for holding the elements to be added and 1 for holding the sum, and ask the user the enter the value for the first two arrays. Then, you need to call your programmer defined function and pass the three arrays to it Now your function needs to compute the sum from the elements of the first two array and store in the third array. Display the elements of the sum array that in your main function.

Explanation / Answer

/* Student had not defined any language,by default i have done this in java
please let me know in case any issue */

import java.util.*;
public class HelloWorld{

public static void main(String []args){
Scanner input=new Scanner(System.in);
int arr1[]=new int[5]; /* defining first array */
int arr2[]=new int[5]; /* defining second array */
int sum[]=new int[5]; /* defining sum array to store the result */
/* asking user to enter elements */
System.out.println("Enter 5 integer values for the first input array : ");
for(int i=0;i<5;i++)
arr1[i]=input.nextInt();
System.out.println("Enter 5 integer values for the second input array : ");
for(int i=0;i<5;i++)
arr2[i]=input.nextInt();
  
/* calling function to calculate sum by passing 3 arrays as parameters */
result(arr1,arr2,sum);
/* printing the sum */
System.out.println("Calculated sum : ");
for(int i=0;i<5;i++)
System.out.println(sum[i]+" ");

  
}
/* function to calculate sum of 2 array */
public static void result(int[] arr1,int[] arr2,int[] sum){
for(int i=0;i<5;i++)
sum[i]=arr1[i]+arr2[i]; //calculating sum
}
}

/*********OUTPUT************
Enter 5 integer values for the first input array :
1 2 3 4 5   
Enter 5 integer values for the second input array :   
5 4 3 2 1   
Calculated sum :
6   
6   
6   
6   
6
********OUTPUT***************/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote