# Sum of any series

Page 1 of 1

## 1 Replies - 1861 Views - Last Post: 29 December 2011 - 05:18 PM

### #1 atik97

• ???

Reputation: 144
• Posts: 715
• Joined: 16-September 08

# Sum of any series

Posted 20 March 2009 - 02:25 PM

Description:
```puts "Enter Number of Terms"
n=gets.chomp
n=n.to_f
puts "Enter 1st Term"
a=gets.chomp
a=a.to_f
puts "Enter 2nd Term"
b=gets.chomp
b=b.to_f
puts "Enter 3rd Term"
c=gets.chomp
c=c.to_f
d1=b-a
d2=c-b
r1=b/a
r2=c/b

if d1==d2
s=(n/2)*(2*a+(n-1)*d1)
puts "The sum of the series is "+s.to_s

elsif r1==r2
s=(a*(r1**n-1))/(r1-1)
puts "The sum of the series is "+s.to_s

else
puts "This is not a valid series!"
end

```

Is This A Good Question/Topic? 0

## Replies To: Sum of any series

### #2 Karel-Lodewijk

Reputation: 455
• Posts: 864
• Joined: 17-March 11

## Re: Sum of any series

Posted 29 December 2011 - 05:18 PM

Note that this only calculates the sum for arithmetic series, meaning series for which the the next term is found by adding or subtracting a constant. Please change the title to reflect this.