当前位置:网站首页>清览题库--C语言程序设计第五版编程题解析(1)
清览题库--C语言程序设计第五版编程题解析(1)
2022-08-10 05:29:00 【我不叫内谁】
目录
题目一(中等)
求时刻时针和分针的夹角
常见的钟表一般都有时针和分针,在任意时刻时针和分针都形成一定夹角;现已知当前的时刻,编写程序求出该时刻时针和分针的夹角(该夹角大小≤180°)。当前时刻值输入格式为“小时:分”,例如:11:12。
输入用例:
11:12
输出用例:
96.00
作答
1.解题思路
观察时钟共有12个大的空隙,每个大的空隙之间有5个小的空隙,即用360°/12*5
推导出每分钟跨过的距离是6°
先推时针,由题目的输入用例可知,当11:12时,时针“正好”指在11的数字上,即走过11*5*6=330°。
再推分针,分针相对较为简单,12分即为12*6°=72°
但是,如果分针转动至12分处,时针必定也会相对偏转,不会正好指在11这个数字上,浅列个比例关系:12分时对应的72°/整个的360°=时针在11之后偏转的角度/每5分钟对应的角度5*6°=30°
推导出时针偏转至336°。
所以二者之间所差角度为360°-336°+72°
(我代码被删了,草)
2.代码
#include <stdio.h>
int main()
{
int h, m, n, p;
double z;//最后输出要求是浮点数,提前double
scanf_s("%d:%d", &h, &m);//正常情况下应用scanf,但VS2022本身不承认scanf,只承认scanf_s,据说是安全性的问题
p = m * 6;//分钟直接用输入的数字×每分钟对应的角度。
n = h * 5 * 6 + p * 30 / 360;//时针×每个大空隙每个大空隙中的小空隙对应的角度+通过比例求出的角度
z = 360 - n + p;//求角度差
printf("%.2lf", z);//输出时要求保留小数点后两位,通过.2实现
return 0;
}
附:答案
#include <stdio.h>
#include <math.h>
int main()
{
int h, m;
double a;
scanf( "%d:%d", &h, &m );
if ( h >= 0 && h <= 12 && m >= 0 && m <= 59 )
{
double a1, a2; /* 时针和分针以0点为起点走过的角度 */
a2 = m * 1.0 / 60 * 360;
a1 = h * 1.0 / 12 * 360 + m * 1.0 / 60 * 30;
a = fabs( a2 - a1 );
a = a > 180 ? 360 - a : a;
printf( "%.2lf", a );
}else
printf( "input error" );
return(0);
}
题目二(简单)
求圆周长、圆面积、圆球表面积、圆球体积、圆柱体积
设圆半径r=1.5,圆柱高h=3,求圆周长、圆面积、圆球表面积、圆球体积、圆柱体积。编写程序用scanf输入数据,输出计算结果;输出时要求有文字说明,取小数点后2位数字。
输入用例:
1.53 4.23
输出用例:
圆周长:9.61 圆面积:7.35 圆球表面积:29.40 圆球体积:14.99 圆柱体积:31.09
作答
1.解题思路
这个没啥解题思路,数学公式别记错就行。
2.代码
#include <stdio.h>
int main() {
double r,h;
double z = 3.14;
scanf("%lf %lf",&r,&h);
printf("圆周长:%0.2lf\n",2*z*r);
printf("圆面积:%0.2lf\n",z*r*r);
printf("圆球表面积:%0.2lf\n",4*z*r*r);
printf("圆球体积:%0.2lf\n",(4*z*r*r*r)/3);
printf("圆柱体积:%0.2lf\n",z*r*r*h);
}
附:答案
#include <stdio.h>
#define PI 3.14
int main()
{
double r, h, l, s, ss, qv, v;
scanf( "%lf%lf", &r, &h );
if ( r > 0 && h > 0 )
{
l = 2 * PI * r;
s = PI * r * r;
ss = 4.0 * PI * r * r;
qv = 4.0 / 3 * PI * r * r * r;
v = PI * r * r * h;
printf( "圆周长:%.2lf\n圆面积:%.2lf\n圆球表面积:%.2lf\n圆球体积:%.2lf\n圆柱体积:%.2lf\n", l, s, ss, qv, v );
}else
printf( "input error" );
return(0);
}
边栏推荐
- aliases节点分析
- SQLSERVER 2008 parses data in Json format
- FPGA engineer interview questions collection 11~20
- conda创建虚拟环境方法和pqi使用国内镜像源安装第三方库的方法教程
- 顺序表的删除,插入和查找操作
- 25张炫酷交互图表,一文入门Plotly
- pytorch框架学习(5)torchvision模块&训练一个简单的自己的CNN (二)
- FPGA engineer interview questions collection 1~10
- Qiskit 学习笔记2
- `id` bigint(20) unsigned NOT NULL COMMENT 'Database primary key',
猜你喜欢
summer preschool assignments
【Static proxy】
一文带你搞懂OAuth2.0
利用PyQt5制作YOLOv5的GUI界面
How does Jenkins play with interface automation testing?
我用这一招让团队的开发效率提升了 100%!
树莓派入门(4)LED闪烁&呼吸灯
论文精度 —— 2016 CVPR 《Context Encoders: Feature Learning by Inpainting》
pytorch框架学习(4)torchvision模块&训练一个简单的自己的CNN (一)
An article to master the entire JVM, JVM ultra-detailed analysis!!!
随机推荐
How cursors work in Pulsar
strongest brain (1)
FPGA engineer interview questions collection 31~40
Advanced Feature Selection Techniques in Linear Models - Based on R
大佬们,mysql cdc(2.2.1跟之前的版本)从savepoint起有时出现这种情况,有没有什
论文精读 —— 2021 CVPR《Progressive Temporal Feature Alignment Network for Video Inpainting》
Attention candidates for the soft exam! The detailed registration process for the second half of 2022 is coming!
MongoDB 基础了解(一)
顺序表的删除,插入和查找操作
SSM框架整合实例
summer preschool assignments
Pulsar中游标的工作原理
Get started with the OAuth protocol easily with a case
Qiskit 学习笔记2
Guys, is it normal that the oracle archive log grows by 3G in 20 minutes after running cdc?
通过一个案例轻松入门OAuth协议
Zhongang Mining: Strong downstream demand for fluorite
Stacks and Queues | Valid parentheses, delete all adjacent elements in a string, reverse Polish expression evaluation, maximum sliding window, top K high frequency elements | leecode brush questions
Transforming into a product, is it reliable to take the NPDP test?
基于Qiskit——《量子计算编程实战》读书笔记(四)