Ask Question
10 May, 06:33

Given an array of ints named x and an int variable named total that has already been declared, write some code that places the sum of all the elements of the array x into total. Declare any variables that you need.

+3
Answers (1)
  1. 10 May, 07:46
    0
    Following are the code:

    Code:

    total = 0; / /assign value to total variable.

    for (int i=0; i
    {

    total=total+x[i]; / /add all array elements in total variable.

    }

    Explanation:

    In the following question, it is defined that x and total is variable. Where variable x is an integer type array and total is an integer variable. we define some code for calculating the sum of the array element. In the above code, we use for loop that calculates sum of array elements that can be described as:

    To calculate the sum we use the total variable. In total variable, we assign value 0. Then we define for loop in loop we use total variables that add all array (x[]) elements.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Given an array of ints named x and an int variable named total that has already been declared, write some code that places the sum of all ...” in 📙 Computers & Technology 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