1. Engineering
  2. Computer Science
  3. c write a program that adds two fourvariable arrays together...

Question: c write a program that adds two fourvariable arrays together...

Question details

C#

Write a program that adds two four-variable arrays together. The first array should be initialized with values 4, 1, 3, and 2. The user should be prompted to enter the values for the second array, be sure to check for invalid input data (see sample execution below).

Both arrays should be passed as arguments to a method named addArrays, which adds corresponding elements of each array together and leaves the result in the second array. The second array should then be printed out in method Main. For instance, if the user enters the values 2, 9, 6, 1 for the second array, after the arrays are passed to addArrays, the values in the second array should be 6, 10, 9, and 3.

SAMPLE EXECUTION

Enter number 1: 2

Enter number 2: g

Invalid input: only whole numbers are allowed

Enter number 2: 9

Enter number 3: 7.8

Invalid input: only whole numbers are allowed

Enter number 3: 6

Enter number 4: 1

Here are the numbers in the first arrays: 4 1 3 2

Here are the numbers in the second arrays: 2 9 6 1

Here are the numbers in the second array after calling addArrays: 6 10 9 3

Press any key to close...

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution