Author Topic: Calculate Sum & Average of Elements in Array.  (Read 8267 times)

Vivek Indripala

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 8
    • View Profile
Calculate Sum & Average of Elements in Array.
« on: March 19, 2019, 07:22:48 AM »
Purpose: Calculate Sum & Average of elements in Array.

Liquid UI Code:

var array_sum = 0; 
var averge;
var num = [23,65,89,54,74];
var array_length = num.length; 
for(var k=0;k<num.length;k++)
   {          
      if(num[k] > 0)
         {
            array_sum = array_sum + num[k];      
         }   
}      
average = array_sum/array_length;     
println("Sum of integers in Array="+array_sum);
println("Average of Integers in Array="+average);