Find prime numbers in the first half and second half of an array | Function to check if a number is prime or not ; Function to find whether elements are prime or not ; Traverse in the given range ; Check if a number is prime or not ; Function to print the prime numbers in the first half and second half of an array ; Driver Code ; Function call
def prime ( n ) : NEW_LINE INDENT for i in range ( 2 , n ) : NEW_LINE INDENT if i * i > n : NEW_LINE INDENT break NEW_LINE DEDENT if ( n % i == 0 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def prime_range ( start , end , a ) : NEW_LINE INDENT for i in range ( start , end ) : NEW_LINE INDENT if ( prime ( a [ i ] ) ) : NEW_LINE INDENT print ( a [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT def Print ( arr , n ) : NEW_LINE INDENT print ( " Prime ▁ numbers ▁ in ▁ the " , " first ▁ half ▁ are ▁ " , end = " " ) NEW_LINE prime_range ( 0 , n // 2 , arr ) NEW_LINE print ( ) NEW_LINE print ( " Prime ▁ numbers ▁ in ▁ the " , " second ▁ half ▁ are ▁ " , end = " " ) NEW_LINE prime_range ( n // 2 , n , arr ) NEW_LINE print ( ) NEW_LINE DEDENT arr = [ 2 , 5 , 10 , 15 , 17 , 21 , 23 ] NEW_LINE n = len ( arr ) NEW_LINE Print ( arr , n ) NEW_LINE