Ask Question
24 August, 09:50

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.

+4
Answers (1)
  1. 24 August, 13:32
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers