当前位置:网站首页>Electronic Association C language level 1 34, piecewise function

Electronic Association C language level 1 34, piecewise function

2022-07-04 07:05:00 dllglvzhenfeng

Electronics Association C Language 1 level  34 、 Piecewise functions

OpenJudge - 13: Piecewise functions


C++ Code :

/*
 Electronics Association  C Language  1 level   34 、 Piecewise functions  
http://noi.openjudge.cn/ch0104/13/

 Programming , Calculate the following piecewise functions  y=f(x) Value .
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
 Input 
 A floating point number  N,0 <= N < 20
 Output 
 Output  N  Corresponding piecewise function value :f(N). Keep the result to three decimal places .
 The sample input 
1.0
 Sample output 
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 Code :

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))


【 Strong base project 】 Some videos of calculus in mathematics and physics competitions

【 Strong base project 】 Some videos of calculus in mathematics and physics competitions _dllglvzhenfeng The blog of -CSDN Blog

Strong base project Mathematics books recommend

Strong base project Mathematics books recommend _dllglvzhenfeng The blog of -CSDN Blog



NOC C++ National primary and secondary school information technology innovation and practice competition (NOC): Software creative programming track

NOC C++ National primary and secondary school information technology innovation and practice competition (NOC): Software creative programming track _dllglvzhenfeng The blog of -CSDN Blog _noc Software creative programming

02 Schedule :

Time signing up :2022 year 1 month -4 month

Tryout time :2022 year 5 month

National finals :2022 year 7 month -8 month ( Time and place to be notified )

2021 year 8 month NOC National primary and secondary school information technology innovation and practice competition Software creative programming primary school senior group Python Analysis of final questions

2021 year 8 month NOC National primary and secondary school information technology innovation and practice competition Software creative programming primary school senior group Python Analysis of final questions _ And non school blog -CSDN Blog _noc python

2022 year 3 Monthly Institute of Electronics Python Grade examination papers ( second level ) Analysis of the answer

2022 year 3 Monthly Institute of Electronics Python Grade examination papers ( second level ) Analysis of the answer _A- Pin children's programming blog -CSDN Blog _ China Electronics Society python second level

原网站

版权声明
本文为[dllglvzhenfeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207040657276145.html

随机推荐