write a program to arrange numbers in increasing order of a list without using sort function.

l1=[]
h=int(input("how many no. you want to enter "))
for i in range(h):
    n=int(input("enter the no. "))
    l1.append(n)
print("entered list is",l1)
for i in range(h):
    for j in range(i+1,h):
        if l1[i]>l1[j]:
            t=l1[i]
            l1[i]=l1[j]
            l1[j]=t
print(l1)
OUTPUT---
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
= RESTART: C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\sorting without sort().py
how many no. you want to enter 5
enter the no. 4
enter the no. 2
enter the no. 6
enter the no. 1
enter the no. 3
entered list is [4, 2, 6, 1, 3]
[1, 2, 3, 4, 6]
>>> 

Leave a Reply

Back To Top