Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
3,240 views
in Online Assessments by Expert (115,900 points) | 3,240 views

1 Answer

0 like 0 dislike

Question 1 : Given an array , find the number of odd elements and even elements in the array and print both the counts separated by a space.

 

# Python3 program to count number of
# even and odd elements in an array

def CountingEvenOdd(arr, arr_size):
    even_count = 0
    odd_count = 0

    # loop to read all the values
    # in the array
    for i in range(arr_size):

        # checking if a number is
        # completely divisible by 2
        if (arr[i] & 1 == 1):
            odd_count += 1
        else:
            even_count += 1

    print("Number of even elements = ",
        even_count)
    print("Number of odd elements = ",
        odd_count)

# Driver Code
arr = [2, 3, 4, 5, 6]
n = len(arr)

# Function Call
CountingEvenOdd(arr, n)


 

Question 2 : Will be uploaded.

by Expert (115,900 points)