Puzzle C9

Sum of Parameters

Write a program that computes the sum of all the floating point numbers on the command line.

C:\Source\>sum +45.3 -12 89.4 -23.56 123
sum: 222.140000

Note that the user might enter numbers without decimal points and numbers with leading + or - signs. This is fine. atof() can be used with these strings. Two or more +- signs will not work, though, and atof() will return 0.0 for such strings.



Previous Page        Answer         Next Page         Home