My son ask me a math question and I can't answer it because I'm too old to remember this. Can anybody help me to solve this and i can help my son to find the answer. thanks in advance
so here the question : ` 1. given $$a = 10$$ $$b = 20$$ then $$a = a + b$$ $$b = a + b$$ Find $a,b$.
- given $$a = 0$$ $$i = 1$$
$$a = a + 0$$ $$i = a + i$$ loop it five time. Then $a = ??$`
Interpreting the math as a computer program, which is often called pseudocode, we have:
$\quad a \leftarrow 10$
$\quad i \leftarrow 20$
$\quad a \leftarrow a+b \quad \textbf{a=10+20=30}$
$\quad b \leftarrow a+b \quad \textbf{b=30+20=50}$
I've added comments in bold, hoping that this makes things more clear. So at the end of this code, we have $a=30$ and $b=50$. For the next code, I've added a loop:
$\quad a \leftarrow 0$
$\quad i \leftarrow 1$
$\quad$ For $j=1$ to $5$ Do
$\quad \quad a \leftarrow a+0 \quad \textbf{a=a}$
$\quad \quad i \leftarrow a+i \quad \textbf{i=1+0=1}$
$\quad$ EndFor
We can observe that $a$ does not change in the loop, since we always add $0$ to $a$, which equals $a$. So we can basically ignore $a$, which I hope is clear.
Then, having this intuition, we see that $i$ will not change in the loop, since we always add $0$ to it. So no matter how many times we loop, $i$ will always be equal to $1$.