Ask Question
1 November, 18:01

Write a program that declares an array alpha of 50 components of type double. Initialize the array so that the first 25 components are equal to the square of the index variable, and the last 25 components are equal to three times the index variable.

+2
Answers (1)
  1. 1 November, 20:27
    0
    The solution code is written in Java.

    double [] alpha = new double[50]; for (int i = 0; i < 25; i++) { alpha[i] = i * i; } for (int j = 25; j < 50; j++) { alpha[j] = j * 3; }

    Explanation:

    Firstly, the syntax to declare an array variable alpha of type double and initialize it with 50 components is presented in Line 1.

    Next, use a for-loop to traverse through the first 25 components (Line 3). Use * operator to multiply index variable by itself (to square it) and assign it to the current component of the alpha array (Line 4).

    Create another for-loop to traverse through the last 25 components (Line 7). This time, multiply the index variable with 3 and assign it to the current component of the alpha array (Line 8).
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that declares an array alpha of 50 components of type double. Initialize the array so that the first 25 components are ...” in 📙 Engineering if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers