This is a classic bars and bars problem. Refer this link to understand this concept
In context to this problem, this is how it is solved using stars and bars.
There are 10 identical sweets.
_ _ _ _ _ _ _ _ _ _
(In analogy to stars and bars, these are the stars)
Now, these 10 sweets are distributed among 3 children say A,B and C
Let's put 2 bars in between those places (Thereby dividing the 10 sweets into 3 sections. Each section determines how many sweets a child gets). Such that, to the left of bar 1 are sweets of A. Between the bars is sweets of B. Sweets to the right on bar 2 are C's.
Consider this one possible arrangement
_ _ _ | _ _ _ _ | _ _ _
Thus A gets 3 here, B gets 4 and C gets 3.
Now, these 2 bars can be anywhere (for 2nd case when you don't have any restriction).
So, give them slots too.
Now, we have 10+2 = 12 slots (In general n+k-1)
We have to choose 2 positions for bars (In general k-1)
Hence we have the formula
(They are equal due to combination property)
Similarly, by restricting the positions of bars (for case 1) you can find the answer.