Space separated values sum


/ Published in: Perl
Save to your folder(s)

Program that sums all the values (including big positive/negative integers)


Copy this code and paste it in your HTML
  1. use strict;
  2. use warnings;
  3. use Math::BigInt;
  4.  
  5. while(<>)
  6. {
  7. s/^ +//g;
  8. my @values = split /\s+/;
  9. my $elemento;
  10. my $sum = Math::BigInt->new('0');
  11. foreach $elemento (@values)
  12. {
  13. $sum->badd(Math::BigInt->new($elemento));
  14. }
  15. print "$sum\n";
  16. $sum=0;
  17. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.