当前位置:网站首页>清览题库--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);
}边栏推荐
- Qiskit 学习笔记2
- Error when installing oracle rac 11g and executing root.sh
- Interface documentation evolution illustration, some ancient interface documentation tools, you may not have used it
- MySql's json_extract function processes json fields
- `id` bigint(20) unsigned NOT NULL COMMENT 'Database primary key',
- pytorch learning
- ThreadPoolExecutor thread pool principle
- 我用这一招让团队的开发效率提升了 100%!
- The sword refers to Offer 033. Variation array
- 【Static proxy】
猜你喜欢
随机推荐
flinkcdc 读取pgsql 的时间被放大了 有大佬知道咋回事吗 gmt_create':1
如何用Apifox 的智能Mock功能?
Conda creates a virtual environment method and pqi uses a domestic mirror source to install a third-party library method tutorial
如何在报表控件FastReport.NET中连接XLSX 文件作为数据源?
FPGA工程师面试试题集锦21~30
聊聊 API 管理-开源版 到 SaaS 版
Stacks and Queues | Implementing Queues with Stacks | Implementing Stacks with Queues | Basic Theory and Code Principles
Arduino框架下合宙ESP32C3 +1.8“tft 网络时钟
Pony语言学习(七)——表达式(Expressions)语法(单篇向)
Talk about API Management - Open Source Edition to SaaS Edition
一篇文章带你搞懂什么是幂等性问题?如何解决幂等性问题?
FPGA engineer interview questions collection 11~20
WSTP初体验
SQL Server query optimization
The time for flinkcdc to read pgsql is enlarged. Does anyone know what happened? gmt_create':1
在vscode中屏蔽Alt热键
实战小技巧19:List转Map List的几种姿势
Interface documentation evolution illustration, some ancient interface documentation tools, you may not have used it
Attention candidates for the soft exam! The detailed registration process for the second half of 2022 is coming!
Linear Algebra (4)








