Tuesday, May 3, 2011

RUBY

Program For Reverse String



class Reverse
puts "Enter the number"
a=gets.chomp.to_i
while a>0
b=a%10
print b
a=a/10
end
end


//Fibonacci series

class Fibo
puts "enter the number"
a=gets.chomp.to_i
f1=0
f2=1
f3=1
puts "Fabonacci series upto numbers #{a+3}"
puts f1
puts f2
for i in 1..a
puts f3

f1=f2
f2=f3
f3=f1+ f2
end
puts f3
end


// FACTORIAL
class Fact
puts "Enter the number "
a=gets.chomp.to_i
c=1
if a==0
puts "the value of fact:#{c}"
end
if a>0
for fact in 1..a-1
a=a*fact
end
puts "the value of fact:#{a}"
end
end

//n TIMES
class Times
n=10
n.times{|i| print i}
end
// print string
class String
str= ["hello", "you", " are " , "welcomed" , " to", "mumbai" ]
for prt in 0...str.length
print prt,":" , str[prt],"\n";
end
end

//switch case
class Result
grade =9
school = case grade
when 5
"B"
when 8
"A"
when 9
"EX"
else
"college"
end
puts "grade #{grade} is in #{school}"
end

// KIND
class Each
gbu=%w( SICT SBT SMBA SS )
gbu.each{|kind| print kind}
end