#Program to determine the median of n given numbers:
n=input("Enter the no. of terms:")
n=int(n)
x=[]
for i in range (0,n):
m=input("enter the no."+str(i+1)+":")
m=float(m)
x.append(m)
for i in range (0,n):
for j in range(i+1,n):
if x[i]>x[j]:
a=x.pop(j)
x.insert(i,a)
print("Sorted elements in ascending order are:\n",x)
if n%2==0:
c=(x[int(n/2)]+x[int((n/2)-1)])/2.0
else:
c=x[int((n-1)/2)]
print("Median of the given numbers is:",c)
n=input("Enter the no. of terms:")
n=int(n)
x=[]
for i in range (0,n):
m=input("enter the no."+str(i+1)+":")
m=float(m)
x.append(m)
for i in range (0,n):
for j in range(i+1,n):
if x[i]>x[j]:
a=x.pop(j)
x.insert(i,a)
print("Sorted elements in ascending order are:\n",x)
if n%2==0:
c=(x[int(n/2)]+x[int((n/2)-1)])/2.0
else:
c=x[int((n-1)/2)]
print("Median of the given numbers is:",c)
Comments
Post a Comment