How to determine what will be equal to K at the end of our actions according to the algorithm?
Closed due to the fact that it was off-topic by the participants default locale , Suvitruf ♦ , freim , vmchar , Kromster May 27 at 11:48 .
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
- " Learning tasks are allowed as questions only on the condition that you tried to solve them yourself before asking a question . Please edit the question and indicate what caused you difficulties in solving the problem. For example, give the code you wrote, trying to solve the problem "- Suvitruf, vmchar
- Explain why. - Semyon
- since A <> B OR A <> C we will go along the "YES" branch Since A> B + C we will go along the "YES" branch Then A = 20 K will increase by 1 Learn to read the block diagram -
- Speech no tupanul did not see that it was a cycle - YYY
- @ ЫЫЫ Learn to read flowcharts - alexlz
|
2 answers
All numbers A, B, C will become equal to 1. Just repeat the specified actions until all values are equal. It turns out like this: (A, B, C) will be consistently
(25, 2, 3)->(20, 2, 3)->(15, 2, 3)->(10, 2, 3)-> (5, 2, 3)->(5, 1, 3)->(1, 1, 3)->(1, 1, 1),
after which the transition to the end.
With other initial data, this algorithm can reach negative numbers and loop (that is, the cycle will not end).
The cycle will be repeated 8 times, so at the end k = 9
|
7
(k, a, b, c) = (0, 25, 2, 3) while a != b or a != c: if a > b + c: a = a - b - c elif a == b + c: b = c - b else: c = c - a - b k = k + 1 print k, a, b, c
|