Ask Question
13 November, 18:34

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. 13 November, 18:53
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers