Python / 1B.py
Madhan-Alagarsamy's picture
Upload 1B.py
ecd5232 verified
raw
history blame contribute delete
717 Bytes
def binary_sum(S, start, stop):
if start>=stop:
return 0
elif start == stop-1:
return S[start]
else:
mid= (start+stop)//2
return binary_sum(S, start, mid)+binary_sum(S, mid,stop)
print("\t summing the elements of a sequence using binary recursion")
print("\t -----------------------------------------")
S=[]
print("Input")
print("- - - - -")
n=int(input("enter the no of elements:"))
print("Enter the elements one by one:")
for i in range(n):
m=int(input())
S.append(m)
print("The given sequence of elements=",S)
r=binary_sum(S, 0, n)
print("output")
print("- - - - - -")
print("The given sum of sequence of elements=",r)