Ask 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 the elements of the array x into total. Declare any variables that you need.

+5
Answers (1)
  1. 17 August, 00:45
    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?
Find 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 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