Hi,
Can you please help me on this issue, I have seen your mail id from ruby
forum.
I am using ruby program for summing up all the numbers from array.
Unfortunately it is returning two values instead of one value.??
Can you please help me on this....
I appreciate your help on this..:)
Input to array:
9989
9991
19980 -> it summing above two numbers
9990
9989
19979 -> it is summing these two numbers
all 4 numbers shoud add and retunr one value but , my ruby program
returning two values saparately(19980 ,19979 )
sum.rb code
----
module Enumerable
# sum of an array of numbers
def sum
return self.inject(0){|acc,i|acc +i}
end
end # module Enumerable
numbers = []
print "\n"
ARGV.each { |num|
i = Float(num)
numbers << i
}
#n=numbers.sum.to_i
#print n.to_s.gsub(/(\d)(?=\d{3}+(?:\.|$))(\d{3}\..*)?/,'\1,\2')
print numbers.sum.to_i
#print "\n"
---Delete ReplyReply ForwardMove
--
Posted via http://www.ruby-forum.com/.