PTA C language 7-6 cm converted to FT in

Time:2021-4-13

7-6 cm to FT in

If the values of foot and inch are known, the corresponding meter is (foot + inch / 12) × 0.3048. Now, if the user enters centimeters, what are the feet and inches corresponding to the English length? Don’t forget that one foot is 12 inches.

analysis

The first time I see this problem, I will be confused by the formula
In fact, it means to give you a few feet and inches to find the corresponding height (meters).
For example, 5 feet 7 feet, according to the formula height = (foot + inch / 12) × 0.3048 = > (5 + 7 / 12) × 0.3048 = 1.7018m
Now, on the other hand, I’ll give you the final height and let you find the corresponding feet and inches.
We observe the formula and find that the so-called several inches have been divided for you.
Why do you say that? One last word: don’t forget that one foot is 12 inches. That is to say, if theinch/12If it’s greater than 1, it’s converted to 1 foot, so it’s the fractional part of the foot.
And the foot in the formula is the integral part.

code

#include 

int main()
{
    int cm;
	scanf("%d", &cm);
	Int foot = cm / 30.48; // M / 100.0/0.3048 divide by / to get the integer part
	//Subtract the integer from the total to get the decimal part, inch / 12, and multiply by 12 to get inch
	int inch = (cm/30.48-foot)*12; 
    printf("%d %d", foot, inch);
	return 0;
}