And Sir gave a another task, huh.. It’s like print the Sun of N numbers.
# To print sum of N natural numbers =begin Program name: natural_numbers.rb Date written: 18-12-2010 Date last modified: 18-12-2010 Author: Tha.Suresh License: Free BSD =end # Main part of the program starts here puts print " Enter the number: " number=gets.chomp.to_i sum = 0 for iterator in 1..number do sum = sum + iterator end puts puts " Sum of N numbers is " + sum.to_s # Main of the program ends here
[root@mercury suresh_class]# ruby natural_numbers.rb
Enter the number: 9
Sum of N numbers is 45