n=5# the size of the arraya=Array.new# creating a blank arayputs"Enter the numbers"foriin(0...n)a<<gets.to_i# getting user input and pushing that into the arrayendforiin(0...n)min=a[i]# storing the a[i] value in min for tracking the lower valueloc=i# storing the i's locationforjin(i+1...n)ifa[j]<minmin=a[j]loc=jendend# swapping the lowest no temp=a[i]a[i]=mina[loc]=tempendputs"The sorted array"# printing the numbers a.each_indexdo|x|print" #{a[x]}"endputs
Top comments (0)
Subscribe
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)