Algorithm to a problem, please help?

2015-09-03 7:04 pm
I need to find the solution.

x+y=z

1+2=3
3+3=6
6+4=10
10+5=15
15+6=21
更新1:

I need to find an equation that will allow me to enter X and solve for Y, or vice versa

回答 (1)

2015-09-03 7:08 pm
f(n) = f(n - 1) + n ; where f(1) = 1

This is a recursive function, a function that calls itself until it meets the exit condition. So if we start with solving for f(6) and want to find its value (which you state above is 21), it would look like this:

f(n) = f(n - 1) + n
f(6) = f(6 - 1) + 6
f(6) = f(5) + 6
f(6) = f(5 - 1) + 5 + 6
f(6) = f(4) + 11
f(6) = f(4 - 1) + 4 + 11
f(6) = f(3) + 15
f(6) = f(3 - 1) + 3 + 15
f(6) = f(2) + 18
f(6) = f(2 - 1) + 2 + 18
f(6) = f(1) + 20
f(6) = 1 + 20
f(6) = 21

And I get the same thing that you get


收錄日期: 2021-04-21 13:55:32
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20150903110447AAMMeUH

檢視 Wayback Machine 備份