You are on page 1of 5

Experiment : 2

Program-1 : Reverse array in python

arr = [2,5,4,6,8]
print("Original array: ", arr)
res = arr[::-1]
print("Reverse array: ", res)

Output:
Program-2 : Find largest element of array

arr = [25, 11, 7, 75, 56];


max = arr[0];
for i in range(0, len(arr)):
if(arr[i] > max):
max = arr[i];
print("Largest element present in given array: ",max);

Output:
Experiment : 3
Program-1: Swap two elements in list
A = [2,5,6,3,9]
B = [12,15,16,13,19]
temp = 0
temp = A
A = B
B = temp
print("After swapping:")
print("A = ",A)
print("B = ",B)

Output:
Program-2: Sum of number in list

A = [2,5,6,8,9]
sum = 0
for i in range(len(A)):
sum += A[i]
print("Sum of elements of List = "+str(sum))

Output:
Program-3: Find even numbers in list

A = [2,5,7,8,12]
print("Even numbers of list : ")
for i in range(len(A)):
if(A[i] % 2 == 0):
print("\t",A[i])

Output:

You might also like