Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. # File: polynomial-1.rb
  2. #
  3. def power_of(a, b)
  4. a * b
  5. end
  6.  
  7. def polynomial(a, b, c, x)
  8. a * power_of(x, 2) + b * x + c
  9. end
  10.  
  11. if ARGV.size != 4
  12. $stderr.puts "Wrong number of arguments. You need to call like this: ruby #{$0} <a> <b> <c> <x>"
  13. $stderr.puts "...you will get back the result of 'a * x ^ 2 + b * x + c'"
  14. exit 1
  15. end
  16.  
  17. a, b, c, x = ARGV.map(&:to_f)
  18. ARGV.clear
  19.  
  20. result = polynomial(a, b, c, x)
  21.  
  22. puts result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement