Ruby program to take a number as input and tells its positive or negative

Views: 142   

Following program shows you how to take a number as input and tells its positive or negative.
In this program we get number from user, and if the number is less than zero it prints negative, and if the number is grater than zero it prints positive

 puts "Please enter a number:"
 input = Integer(gets.chomp)
 if input < 0
 puts "Given number is -ve"
 else
 puts "Given number is +ve"
 end

Output:

Example1:

Please enter a number:
2
Given number is +ve

Example2:

Please enter a number:
-3
Given number is -ve
On By