Class XII - Computer Science Assessed Homework 1
Class XII - Computer Science Assessed Homework 1
Output:
Enter the number: 6
The factorial of 6 is 720
Output:
Enter the number of terms: 7
Fibonacci Sequence:
0
1
1
2
3
5
8
Output:
Enter first number: 36
Enter second number: 24
LCM of 36 and 24 is 72.
Output:
Enter the number: 3
Enter the power: 4
3 power 4 is: 81
def Binary_Search(arr,n,lb,ub,X):
if(lb>ub):
print("Not found!")
else:
mid = int((lb+ub)/2)
if(arr[mid]==X):
print('Element found at position: ',mid+1)
elif(arr[mid]>X):
Binary_Search(arr,n,lb,mid,X);
elif(arr[mid]<X):
Binary_Search(arr,n,mid+1,ub,X);
arr = []
a=int(input('Enter the number of elements: '))
for i in range(a):
arr.append(int(input('Enter the element: ')))
n = len(arr)
X = int(input('Enter the element you want to search: '))
Binary_Search(arr,n,0,n-1,X)
Output:
Enter the number of elements: 7
Enter the element: 2
Enter the element: 65
Enter the element: 789
Enter the element: 324
Enter the element: 5
Enter the element: 1
Enter the element: 51
Enter the element you want to search: 324
Element found at position: 4