Answer:
Following are the code:
Code:
total = 0; //assign value to total variable.
for (int i=0; i<x.length; i++) //for loop
{
total=total+x[i]; //add all array elements in total variable.
}
Step-by-step 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.