Skip to content

Instantly share code, notes, and snippets.

@ravi-ndra
ravi-ndra / String4.rb
Created September 14, 2022 08:55
Program to return String with 'if' aft starting , if string is already have 'if' at beginning return original String.
# program to give new string staring by 'if' , if string already have
# 'if' at starting give unchanged string
puts "Enter String :"
str = gets.chomp
if str[0,2] == 'if'
puts str
else
@ravi-ndra
ravi-ndra / Array11.rb
Last active September 14, 2022 08:55
Program to count all vowels in string!
# take user inout string and find out how many vowels are there in string
puts "Enter a String :"
str = gets.chomp.downcase
cnt = (str.count "a") + (str.count "e") + (str.count "i") + (str.count "o") + (str.count "u")
puts cnt
@ravi-ndra
ravi-ndra / Array10.rb
Last active September 14, 2022 08:56
program to find unique elements in Array !
#Create and array with 10 random values and find uniq elemets from it
arr = Array.new(10)
puts "Enter element for array:"
for i in 0...10
arr[i] = gets.chomp
end
for i in 0...10
for j in 1...10-i
@ravi-ndra
ravi-ndra / Array9.rb
Last active September 14, 2022 08:56
Array program to sort array
# Create array of 10 and sort
arr = Array.new(10)
puts "Enter element for array:"
for i in 0...10
arr[i] = gets.chomp
end
for i in 0...10
for j in 1...10-i