hl

Wednesday, 8 March 2017

Ruby Programming Language Tutorials Lec 02

Tutorial 2


Print statement

       In ruby printing is done simply by typing print and forword by double quotes

                              Input                                                                  Output


Defining integers

     In ruby numbers are declared by simply typing their names such as if you want to take a no from name frist_num so type frist_num and after that your num is declared
 

And if you want to give it some value write " frist_num = 7 "

Taking inputs

     To take inputs from key board write puts and after an space put your integer there and followed by ".to_s"

Use of gets keyword

     Gets is a key word of ruby use to taking inputs 

Use of puts keyword

     Puts is a keyword of ruby use to putting value to integers

A Simple program in ruby of addition of two numbers

     To making a program of adding two numbers is also so eazy .Lets combine all we learned yet printing numbers, defining integers and taking inputs .So lets do it:

print "Enter a Value:"

frist_num = gets.to_i

print "Enter Another Value :"

second_num = gets.to_i

puts frist_num.to_s + " + " + second_num.to_s + " = " + (frist_num + second_num).to_s


Output :


No comments:

Post a Comment