Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .

0 like 0 dislike
3,771 views
in Online Assessments by Expert (144,420 points)

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 (144,420 points)
...