b.
c. d.
1 2 3 4 5 6 7 8 9 10 11
Fill the array with random numbers between 10 and 90 Calculate and print out the sum of the elements in such manner:
- If the element is even divided by 2
- If the element is odd multiply it with 2
Display the array elements in reverse order 4 numbers on each line Create another array B of 12 integer numbers
Then copy the elements of A to B in such manner:
Write the odd numbers first then the even ones
A
13
25
75
35
79
50
60
90
80
40
10
90
def find_pair_of_sum(arr: list, n: int):
map = {}
for i in range(n):
for j in range(i+1, n):
sum = arr[i] + arr[j]
if sum in map:
print(f"{map[sum]} and ({arr[i]}, {arr[j]})")
return
else:
map[sum] = (arr[i], arr[j])
if __name__ == "__main__":
arr = [3, 4, 7, 1, 2, 9, 8]
n = len(arr)
find_pair_of_sum(arr, n)
Comments
Leave a comment