printf returns the number of characters output. %*c means print a character and pad to the width specified by an argument. So printf("%*c", 3, '\r') means to print a carriage return with 2 spaces before it. printf("%*c%*c", n, '\r', m, '\r') therefore prints n + m characters - that's n - 1 spaces to pad the first \r, m - 1 spaces to pad the second \r, and the two carriage returns. That's why it returns 7.
A carriage return takes you back to the start of the line, so after printing those n + m characters the next thing printed will appear at the start of the line. That means "Sum = " overwrites the output of the first printf.