Sum of all the Composite Numbers from Odd indices of the given array | 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 ; Function to check for composite numbers ; Check if the factors are greater than 2 ; Check if the number is composite or not ; Driver code
def odd_indices ( arr ) : NEW_LINE INDENT sum = 0 NEW_LINE for k in range ( 0 , len ( arr ) , 2 ) : NEW_LINE INDENT check = composite ( arr [ k ] ) NEW_LINE sum += arr [ k ] if check == 1 else 0 NEW_LINE DEDENT print ( sum ) NEW_LINE DEDENT def composite ( n ) : NEW_LINE INDENT flag = 0 NEW_LINE c = 0 NEW_LINE for j in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( n % j == 0 ) : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT if ( c >= 3 ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT return flag NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 13 , 5 , 8 , 16 , 25 ] NEW_LINE odd_indices ( arr ) NEW_LINE DEDENT