Skip to main content

Posts

11. Program to calculate COMBINATION and PERMUTATION with simple steps

#program to calculate the combination and permutation def factorial(number):     c=1     if(number==0):         return 1     for i in range(number,0,-1):         c=c*i     return c def combination():     print('welcome to the combination finding')     print()     print('''Our format is as follows: we will ask a and b as aCb  means a combiantion b''')     a=int(input('enter a of the combination'))     b=int(input('enter b of the combination'))     print('you want to find',a,'C',b)     if(a>=b):                  return factorial(a)/(factorial(b)*factorial(a-b))     else:         print('you have written a less than b which is incorrect') def permutation():     print('welcome to the permutation finding')     print('''Our format is as follows:...

10. Program to calculate the factor and to find prime number(combo)

#Program to calculate the factor and to find prime number a=int(input('enter the number')) r=a p=0 print('   ',float(a)) for i in range(2,500):     while(a%i==0):         a=a/i         print(i,'x',a)         p=p+1         if(a==1):             print('Total factors of',r,'is',p) if(p==1):     print(r,'is a prime number') else:     print(r,'is not a prime number ')          OUTPUT:

9. BINARY SEARCH:python program, to search a number without using recursion

def binsearch(ar,key):     low=0     high=len(ar)-1     while low<=high:         mid=int((low+high)/2)         if key==ar[mid]:             return mid         elif key<ar[mid]:             high=mid-1         else:             low=mid+1     else:         return-263256 #main program ra=[12,36,45,58,65,95,99] item=int(input('enter the number to be searched:-')) res=binsearch(ra,item) if res>=0:     print(item,'found at index',res) else:     print('SORRY',item,'NOT FOUND IN ARRAY')

6. Program for binary search using recurison

#program for the binary search def binary(seq,item,l,u):       if l>u:             return -55       mid=int((l+u)/2)       if item== seq[mid] :             return(mid)       elif item< seq[mid] :             u=mid-1             binary(seq,item,l,u)       elif item> seq[mid] :             l=mid+1             binary(seq,item,l,u)       else:             print('you entered wrong number') series=[5,10,12,15,22,28,44,78,89,99,121,143,178,199,231] print('your series is:',series) n=len(series) number=int(input('enter the number from the series to be searched')) result=binary(series,number,0,n-1) if result < 0:       print('you entered negative value')...

5. Python Program to print the sum to factorial of numbers

# write a program to calculate the sum of the factorial of a number. n=int(input('enter the POSITIVE no for which you want factorial')) s=0 if n==0:       print('the factorial of 0 = 1') if n==1:       print('the factorial of 1 = 1') if n>=2:     c=1     for i in range(1,n+1):           for j in range (i,0,-1):                 c=c*j                 s=s+c     print('The factorial of ',n,'is',c) else:       print('You entered wrong value')