text: Sum of all the Composite Numbers from Odd indices of the given array | Function to check for composite numbers ; Check if the factors are greater than 2 ; Check if the number is composite or not ; Function to print the sum of all composite numbers in the array ; Iterate for odd indices in the array ; Check if the number is composite then add it to sum ; return the sum ; Driver code
code: function composite ( n ) { let flag = 0 ; let c = 0 ; for ( let j = 1 ; j <= n ; j ++ ) { if ( n % j == 0 ) { c += 1 ; } } if ( c >= 3 ) flag = 1 ; return flag ; } function odd_indices ( arr , n ) { let sum = 0 ; for ( let k = 0 ; k < n ; k += 2 ) { let check = composite ( arr [ k ] ) ; if ( check == 1 ) sum += arr [ k ] ; } document . write ( sum + " " ) ; } let arr = [ 13 , 5 , 8 , 16 , 25 ] ; let n = arr . length odd_indices ( arr , n ) ;