RUBY COMPLETE FOR EXAM

21 05 2010

puts “+———————–+”
puts “| Pilihan! |”
puts “+———————–+”
puts “| 1. Kalkulator |”
puts “| 2. Bintang |”
puts “| 3. Ganjil Genap |”
puts “| 4. Faktorial |”
puts “| 5. Exit |”
puts “+———————–+”
puts “+———————–+”
print ” Masukkan Pilihan : ”
a=gets.to_i
puts “+———————–+”
if a == 1
puts “+———————-+”
puts “| Program Kalkulator |”
puts “+———————-+”
print “masukkan bilangan ke-1: ”
x=gets.to_i
print “masukkan bilangan ke-2: ”
i=gets.to_i
a=x+i
b=x-i
c=x*i
d=x/i
print x,” + “,i,” = “,a
print “\n”
print x,” – “,i,” = “,b
print “\n”
print x,” * “,i,” = “,c
print “\n”
print x,” : “,i,” = “,d
puts “\n”
elsif a == 2
puts “+———————-+”
puts “| Program Bintang |”
puts “+———————-+”
print “masukkan jumlah baris:”
i=gets.to_i
k=0
for i in 1..i do
for k in 1..i do
print “*”
i=i+1
end
puts ” ”
end
elsif a == 3
puts “+———————-+”
puts “| Program Ganjil Genap |”
puts “+———————-+”
print ” Masukkan Nilai Awal: ”
i=gets.to_i
while i <= 10
print "#{i} itu "
i=i+1
if i <= i^1
print "ganjil"
else
print "genap"
end
puts " "
end
elsif a == 4
puts "+———————-+"
puts "| Program Faktorial |"
puts "+———————-+"
def faktorial(y)
if y==0
return 1
else
return (y*faktorial(y-1))
end
end
print "masukkan nilai awal = "
x = gets.to_i
while x <= 10
print "faktorial #{x} = "
puts faktorial(x)
x=x*2
end
elsif a == 5
exit=true
else
puts “+——————————+”
puts “| created by : andi syuryadinata |”
puts “+——————————+”
end


Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: