Madhan-Alagarsamy commited on
Commit
ecd5232
·
verified ·
1 Parent(s): f6d5e24

Upload 1B.py

Browse files
Files changed (1) hide show
  1. 1B.py +23 -0
1B.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def binary_sum(S, start, stop):
2
+ if start>=stop:
3
+ return 0
4
+ elif start == stop-1:
5
+ return S[start]
6
+ else:
7
+ mid= (start+stop)//2
8
+ return binary_sum(S, start, mid)+binary_sum(S, mid,stop)
9
+ print("\t summing the elements of a sequence using binary recursion")
10
+ print("\t -----------------------------------------")
11
+ S=[]
12
+ print("Input")
13
+ print("- - - - -")
14
+ n=int(input("enter the no of elements:"))
15
+ print("Enter the elements one by one:")
16
+ for i in range(n):
17
+ m=int(input())
18
+ S.append(m)
19
+ print("The given sequence of elements=",S)
20
+ r=binary_sum(S, 0, n)
21
+ print("output")
22
+ print("- - - - - -")
23
+ print("The given sum of sequence of elements=",r)