当前位置:网站首页>电子协会 C语言 1级 34 、分段函数
电子协会 C语言 1级 34 、分段函数
2022-07-04 06:57:00 【dllglvzhenfeng】
电子协会 C语言 1级 34 、分段函数
C++代码:
/*
电子协会 C语言 1级 34 、分段函数
http://noi.openjudge.cn/ch0104/13/
编写程序,计算下列分段函数 y=f(x)的值。
y=-x+2.5; 0 <= x < 5
y=2-1.5(x-3)(x-3); 5 <= x < 10
y=x/2-1.5; 10 <= x < 20
输入
一个浮点数 N,0 <= N < 20
输出
输出 N 对应的分段函数值:f(N)。结果保留到小数点后三位。
样例输入
1.0
样例输出
1.500
*/
#include<iostream>
using namespace std;
int main()
{
double n,y;
cin>>n;
if(n>=0 && n<5)
{
y=-n+2.5;
}
else
{
if(n>=5 && n<10)
{
y=2-1.5*(n-3)*(n-3);
}
if(n>=10 && n<20)
{
y=n/2-1.5;
}
}
printf("%.3lf\n",y);
return 0;
}
python3代码:
n = float(input())
if 0 <= n < 5:
print('%.3f' % (2.5 - n))
elif n < 10:
print('%.3f' % (2 - 1.5*(n - 3)*(n - 3)))
elif n < 20:
print('%.3f' % (n/2 - 1.5))
【强基计划】数学与物理竞赛中的微积分部分视频
【强基计划】数学与物理竞赛中的微积分部分视频_dllglvzhenfeng的博客-CSDN博客
强基计划 数学相关书籍 推荐
强基计划 数学相关书籍 推荐_dllglvzhenfeng的博客-CSDN博客
NOC C++ 全国中小学信息技术创新与实践大赛(NOC):软件创意编程赛道
NOC C++ 全国中小学信息技术创新与实践大赛(NOC):软件创意编程赛道_dllglvzhenfeng的博客-CSDN博客_noc软件创意编程
02赛程安排:
报名时间:2022年1月-4月
选拔赛时间:2022年5月
全国决赛:2022年7月-8月(时间及地点另行通知)
2021年8月NOC全国中小学信息技术创新与实践大赛 软件创意编程小学高年级组Python决赛题解析
2021年8月NOC全国中小学信息技术创新与实践大赛 软件创意编程小学高年级组Python决赛题解析_与非学堂的博客-CSDN博客_noc python
2022年3月电子学会Python等级考试试卷(二级)答案解析
2022年3月电子学会Python等级考试试卷(二级)答案解析_A-别针少儿编程的博客-CSDN博客_中国电子学会python二级
边栏推荐
- Design of test cases
- 2022 wechat enterprise mailbox login entry introduction, how to open and register enterprise wechat enterprise mailbox?
- Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
- 电脑通过Putty远程连接树莓派
- tars源码分析之2
- Selection (021) - what is the output of the following code?
- 金盾视频播放器拦截的软件关键词和进程信息
- [FPGA tutorial case 8] design and implementation of frequency divider based on Verilog
- [FPGA tutorial case 7] design and implementation of counter based on Verilog
- What is the "relative dilemma" in cognitive fallacy?
猜你喜欢
Set JTAG fuc invalid to normal IO port
selenium驱动IE常见问题解决Message: Currently focused window has been closed.
Bottom problem of figure
the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
The final week, I split
How notepad++ counts words
Mysql 45讲学习笔记(七)行锁
Centos8 install mysql 7 unable to start up
The most effective futures trend strategy: futures reverse merchandising
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
随机推荐
关于IDEA如何设置快捷键集
2022年,或許是未來10年經濟最好的一年,2022年你畢業了嗎?畢業後是怎麼計劃的?
Can the out of sequence message complete TCP three handshakes
Google Chrome Portable Google Chrome browser portable version official website download method
Check and display one column in the known table column
selenium驱动IE常见问题解决Message: Currently focused window has been closed.
js 常用时间处理函数
请问旧版的的常用SQL怎么迁移到新版本里来?
2022 is probably the best year for the economy in the next 10 years. Did you graduate in 2022? What is the plan after graduation?
【网络数据传输】基于FPGA的百兆网/兆网千UDP数据包收发系统开发,PC到FPGA
Mysql 45讲学习笔记(六)全局锁
Vulhub vulnerability recurrence 77_ zabbix
Since DMS is upgraded to a new version, my previous SQL is in the old version of DMS. In this case, how can I retrieve my previous SQL?
金盾视频播放器拦截的软件关键词和进程信息
tars源码分析之2
Fundamentals of SQL database operation
Download address of the official website of national economic industry classification gb/t 4754-2017
tars源码分析之1
Deep profile data leakage prevention scheme
[GF (q) + LDPC] regular LDPC coding and decoding design and MATLAB simulation based on the GF (q) field of binary graph