Program to find kth largest number in an array-Python
Now on a new motive to complete the first cycle of programs given at college in Python instead of C,following being the first program I did....................
#program to find kth largest no in an array
n=int(raw_input("\nEnter the limit "))
arr=[]
for c in range (0,n):
print "Enter no ",c+1,
no=int(input())
arr.append(no)
c=0
for c in range (0,n): #bubble sort
for c2 in range (0,n-1):
if arr[c2] > arr[c2+1]:
t=arr[c2]
arr[c2]=arr[c2+1]
arr[c2+1]=t
c=int(raw_input("Enter the value of k "))
if c == 1:
print "%dst largest no is " %(c),arr[c-1]
elif c == 2:
print "%dnd largest no is " %(c),arr[c-1]
elif c == 3 :
print "%drd largest no is " %(c),arr[c-1]
else:
print "%dst largest no is " %(c),arr[c-1]
input()
#program to find kth largest no in an array
n=int(raw_input("\nEnter the limit "))
arr=[]
for c in range (0,n):
print "Enter no ",c+1,
no=int(input())
arr.append(no)
c=0
for c in range (0,n): #bubble sort
for c2 in range (0,n-1):
if arr[c2] > arr[c2+1]:
t=arr[c2]
arr[c2]=arr[c2+1]
arr[c2+1]=t
c=int(raw_input("Enter the value of k "))
if c == 1:
print "%dst largest no is " %(c),arr[c-1]
elif c == 2:
print "%dnd largest no is " %(c),arr[c-1]
elif c == 3 :
print "%drd largest no is " %(c),arr[c-1]
else:
print "%dst largest no is " %(c),arr[c-1]
input()