一道有趣的PAT编程题.c

Question do today, thought for a long time, found very interesting, the original question is as follows :

厘米换算英尺英寸 (15point(s))
如果已知英制长度的英尺foot和英寸inch的值,那么对应的米是(foot+inch/12)×0.3048。现在,如果用户输入的是厘米数,那么对应英制长度的英尺和英寸是多少呢?别忘了1英尺等于12英寸。
输入格式:
输入在一行中给出1个正整数,单位是厘米。
输出格式:
在一行中输出这个厘米数对应英制长度的英尺和英寸的整数值,中间用空格分开。
输入样例:
170

输出样例:
5 6***

Analysis of the Idea :
This question there are three points to note :
(1Although the topic is about the formula for conversion of meters and feet, inches, but requires that the input is measured in centimeters, so pay attention to the conversion of input ;
(2)The title is not asking us to cm separate converted to feet and inches, and asked is : Enter the cm will transform how many inches to many feet, two algorithms are completely different issues, analysis of the specific ideas to the picture below :

在这里插入图片描述****(3)Select the type of data : last of the required output is an integer, therefore, when you define a variable in the application of type int, some people might be defined with a float, but Pat’ll think it’s rounded at compile time, rather than the interception of data, causing the error.
Specific code as follows:
*****

//  date:2020/3/4
//  author:xiezhg5
#include <stdio.h>
int main(void)
{
   int cm,foot,inch;                //定义整形变量 
   scanf("%d",&cm);                 //scanf()接收输入的数据 
   //注意不是单纯的转换
   //foot和inch不是分开的 
   foot=(int)(cm/30.48);           
   inch=(int)((cm/30.48-foot)*12);
   printf("%d %d\n",foot,inch);
   return 0;
}
发布了30 篇原创文章 · 获赞 10 · 访问量 294

猜你喜欢

转载自blog.csdn.net/qq_45645641/article/details/104656609