distance of sun from earth code example Example 1: distance between sun and earth 151.17 million km Example 2: distance from the earth to the sun 1 AU (astronomical unit)