一道有趣的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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值