Then at the end of the first year, the sum of the principal and interest you can get is S = p× (1+r) = p+p× r.
Where p is your principal and p×r is the interest earned on your deposit after 1 year.
The so-called compound interest means that the interest obtained in this period can be used as the principal to calculate new interest in the next period, which is also called "rolling interest"
By the end of the second year, if you still haven't withdrawn your money, you have to calculate the new interest from the interest p×r you earned in 1 year in addition to your principal P.
Then the sum of the principal and interest you can get at the end of the second year is s = p× (1+r)+p× r× (1+r).
Two common factors (1+r) are continuously extracted from the right side of the equation, and after simplification, S = p× (1+R) 2 can be obtained.
By analogy, by the end of the third year, the sum of principal and interest you can get is S = P× (1+R) 3.
Then by the end of the nth year, the sum of the principal and interest you can get is S = p× (1+r) n.