#Program to arrange n numbers in ascending order using Bubble sort algorithm:
n=input("Enter the no. of data:")
n=int(n)
x=[]
s=0
for i in range(n):
m=input("Enter the number "+str(i+1)+":")
m=float(m)
x.append(m)
for i in range(0,n,1):
for j in range (0,n-i-1,1):
if x[j]>x[j+1]:
x[j],x[j+1]=x[j+1],x[j]
s=s+1
print("The entered numbers in ascending order is:\n",x,"\nNo. of swapping required:",s)
n=input("Enter the no. of data:")
n=int(n)
x=[]
s=0
for i in range(n):
m=input("Enter the number "+str(i+1)+":")
m=float(m)
x.append(m)
for i in range(0,n,1):
for j in range (0,n-i-1,1):
if x[j]>x[j+1]:
x[j],x[j+1]=x[j+1],x[j]
s=s+1
print("The entered numbers in ascending order is:\n",x,"\nNo. of swapping required:",s)
Comments
Post a Comment