Answer:
weight = int(input("Enter weight in milligrams: "))
kilograms = int(weight / 1000000)
grams = int((weight - (kilograms * 1000000)) / 1000)
milligrams = weight - ((kilograms * 1000000) + (grams * 1000))
print("{} milligrams are equivalent to {} kilogram(s), {} gram(s), and {} milligram(s)".format(weight, kilograms, grams, milligrams))
Explanation:
*The code is in Python.
Ask the user to enter the weight and set it to the variable weight
Calculate the kilograms, divide the weight by 1000000 and cast the result to the int (If the weight is 1050042, kilograms would be 1050042/1000000 = 1)
Calculate the grams, subtract the kilograms from the weight, divide it by 1000 and cast the result to the int (If the weight is 1050042, grams would be int((1050042 - (1 * 1000000)) / 1000) = 50)
Calculate the milligrams, subtract the kilograms and grams from the weight (If the weight is 1050042, milligrams would be 1050042 - ((1 * 1000000) + (50 * 1000)) = 42)
Print the weight, kilograms, grams, and milligrams in the required format