UNIT III IP
UNIT III IP
x=int(input("Enter X Value"))
y=int(input("Enter Y value"))
rem=x%y
while rem!=0:
x=y
y=rem
rem=x%y
print("GCD of given numbers is:",y)
OUTPUT:
Enter X Value54
Enter Y value24
GCD of given numbers is: 6
print(newtonSqrt(25, 3))
print(newtonSqrt(25, 5))
print(newtonSqrt(25, 10))
Output:
5.01139410653
5.00000000002
5.0
3.python program to find the exponential value of a number.
def power(base,exp):
if(exp==1):
return(base)
if(exp!=1):
return(base*power(base,exp-1))
base=int(input("Enter base: "))
exp=int(input("Enter exponential value: "))
print("Result:",power(base,exp))
OUTPUT:
Enter base: 2
Enter exponential value: 3
Result: 8
OUTPUT:
list = [ 2, 3, 4, 10, 40 ]
x = int(input("Enter the search element"))
result = binarySearch(list, 0, len(list)-1, x)
if result != -1:
print ("Element is present at index ", result)
else:
print ("Element is not present in array")
OUTPUT:
def sum(arr):
total=0
for i in arr:
total=total+i
return total
arr=list(input("Enter the array of numbers"))
tot=sum(arr)
print("sum of array=",tot)
Output:
Enter the array of numbers 4,5,6
sum of array=15)