import random
n = int(input("Enter the size of the array: "))
C = [random.randint(-10, 10) for i in range(n)]
print("Array C:", C)
sum = 0
count = 0
for i in C:
if i % 2 == 0:
sum += i
count += 1
if count == 0:
print("No even numbers found.")
else:
avg = sum / count
print("Average of even numbers:", avg)
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
import random
n = int(input("Enter the size of the array: "))
C = [random.randint(-10, 10) for i in range(n)]
print("Array C:", C)
sum = 0
count = 0
for i in C:
if i % 2 == 0:
sum += i
count += 1
if count == 0:
print("No even numbers found.")
else:
avg = sum / count
print("Average of even numbers:", avg)