/*//ASCII表中的下一个字符#includeusing namespace std;int xiyage(char a){ char b = a + 1; return b;}int main(){ char a; cin >> a; cout << (char)xiyage(a) << endl; return 0;}*//*//输入一个浮点数,输出这个浮点数的绝对值#include#includeusing namespace std;float abs(float x){ float f = x; if (x < 0) { return -f; } return f;}int main(){ float x; cin >> x; cout << setprecision(2) << fixed << abs(x) << endl;}*///给定一个整数N,判断其正负。/*#includeusing namespace std;void fun(int a){ if (a>0) { cout << "positive"; } else if (a<0) { cout << "negative"; } else { cout << "zero"; }}int main(){ int a; cin >> a; fun(a); return 0;}*///给定一个整数,判断该数是奇数还是偶数/*#include using namespace std;void fun(int a){ if (a%2==0) { cout<< "even"; } else { cout< }}int main(){ int a; cin >> a; fun(a); return 0;}*//*编写程序,计算下列分段函数y = f(x)的值。y = -x + 2.5; 0 <= x < 5y = 2 - 1.5(x - 3)(x - 3); 5 <= x < 10y = x / 2 - 1.5; 10 <= x < 20*//*#include #includeusing namespace std;double fun1(double x){ return -x + 2.5;}double fun2(double x){ return 2 - 1.5*(x - 3)*(x - 3);}double fun3(double x){ return x / 2 - 1.5;}double judge(double x){ double z = 0; if (x>=0&&x<5) { z = fun1(x); } else if (x>=5&&x<10) { z = fun2(x); } else { z = fun3(x); } return z;}int main(){ double x; cin >> x; cout << setprecision(3) << fixed << judge(x);}*///给定三个正整数,分别表示三条线段的长度,判断这三条线段能否构成一个三角形。/*#include #includeusing namespace std;void judge(int a, int b, int c){ if (a+b>c&&a+c>b&&b+c>a&&abs(a-b) { cout << "yes"; } else { cout << "no"; }}int main(){ int a, b, c; cin >> a >> b >> c; judge(a, b, c); return 0;}*///判断某年是否是闰年。/*#include using namespace std;void judge(int a){ if (a%100!=0&&a%4==0||a%400==0) { cout << "Y"; } else { cout << "N"; }}int main(){ int y; cin >> y; judge(y);}*///一个最简单的计算器,支持+, -, *, / 四种运算。仅需考虑输入输出为整数的情况,数据和运算结果不会超过int表示的范围。/*#include using namespace std;int fun(int a, int b, char c){ if (c=='+') { return a + b; } if (c == '-') { return a - b; } if (c == '*') { return a * b; } if (c == '/') { return a / b; } else { return 0; }}int main(){ int a=0, b=0; char c=0; cin >> a >> b >> c; if (b==0) { cout << "Divided by zero!"; } if (fun(a,b,c)) { cout << fun(a, b, c); } else { cout << "Invalid operator!"; } return 0;}*//*#include using namespace std;void fun(int a, int b, char c){ switch (c) { case '+': cout << a + b; break; case '-': cout << a - b; break; case '*': cout << a * b; break; case '/': if (b == 0) { cout << "Divided by zero!"; break; } else { cout << a / b; break; } default: cout << "Invalid operator!"; } cout << endl;}int main() { int a, b; char c; cin >> a >> b >> c; fun(a, b, c); return 0;}*///任意输入一个字符,判断其ASCII是否是奇数,若是,输出YES,否则,输出NO/*#include using namespace std;void judge(int a){ if (a%2==0) { cout << "NO"; } else { cout << "YES"; }}int main(){ char a; cin >> a; judge((int)a); return 0;}*//*#include using namespace std;int main(){ char ch; ch = getchar(); if (ch % 2 == 0) cout << "NO" << endl; else cout << "YES" << endl; return 0;}*///根据邮件的重量和用户是否选择加急计算邮费。计算规则//重量在1000克以内(包括1000克), 基本费8元。超过1000克的部分//每500克加收超重费4元,不足500克部分按500克计算;如果用户选择加急,多收5元。/*#include #includeusing namespace std;int main(){ int x,y=0; char c; cin >> x >> c; if (x <= 1000) { y = 8; } else { y = 8 + ceil((x - 1000) / 500.0) * 4; } if (c=='y') { y += 5; } cout << y << endl; return 0;}*///某饮料公司最近推出了一个“收集瓶盖赢大奖”的活动:如果你拥有10个印有“幸运”//或20个印有“鼓励”的瓶盖,就可以兑换一个神秘大奖。//现分别给出你拥有的印有“幸运”和“鼓励”的瓶盖数,判断是否可以去兑换大奖。/*#include using namespace std;int main(){ int x, y; cin >> x >> y; if (x>=10||y>=20) { cout << 1< } else { cout << 0< } return 0;}*//*小金打牌,当对方手里纸牌的张数大于等于10张时,他会观察对方的神情,若对方神情紧张,他就出“炸”,若对方在笑,他就什么牌也不出。字符 'J'表述对方申请紧张,'H'表述对方在笑。小金出“炸”,则输出“Z”,如果什么牌都不出,则输出“pass”。当对方手里纸牌的张数小于10张的时候,他会“接”对方出的牌,也就是对方出“单”,他也出“单”,对方出“双”,他也出双。字符 'D’代表对方出“单”,'S'代表对方出“双”。小金出“单”,则输出“D”,如果出“双”,则输出“S*//*#includeusing namespace std;int main(){ int a; char b,c; cin>>a>>b>>c; if(a>=10) { if(b=='J') { cout< } else { cout< } } else { if(c=='D') { cout< } else { cout< } } return 0;}*///判断一个数n 能否同时被3和5整除/*#includeusing namespace std;int main(){ int n; cin>>n; if(n%3==0&&n%5==0) { cout< } else { cout< } return 0;}*//*给定一个整数,判断它能否被3,5,7整除,并输出以下信息:1、能同时被3,5,7整除(直接输出3 5 7,每个数中间一个空格);2、只能被其中两个数整除(输出两个数,小的在前,大的在后。例如:3 5或者 3 7或者5 7,中间用空格分隔);3、只能被其中一个数整除(输出这个除数);4、不能被任何数整除,输出小写字符‘n’,不包括单引号。*//*#includeusing namespace std;int main(){ int a; cin>>a; if(a%5==0&&a%7==0&&a%3==0) { cout<<3< "<<5< } else if(a%3==0&&a%5==0) { cout<<3< "<<5< } else if(a%3==0&&a%7==0) { cout<<3< "<<7< } else if(a%5==0&&a%7==0) { cout<<5< "<<7< } else if(a%3==0) { cout<<3< } else if(a%5==0) { cout<<5< } else if(a%7==0) { cout<<7< } else { cout< } return 0;}*///晶晶的朋友贝贝约晶晶下周一起去看展览,//但晶晶每周的1、3、5有课必须上课,请帮晶晶判断她//能否接受贝贝的邀请,如果能输出YES;如果不能则输出NO。/*#includeusing namespace std;int main(){ int a; cin>>a; if(a==1||a==3||a==5) { cout< } else { cout< } return 0;}*//*在北大校园里,没有自行车,上课办事会很不方便.但实际上,并非去办任何事情都是骑车快,因为骑车总要找车、开锁、停车、锁车等,这要耽误一些时间.假设找到自行车,开锁并车上自行车的时间为27秒;停车锁车的时间为23秒;步行每秒行走1.2米,骑车每秒行走3.0米。请判断走不同的距离去办事,是骑车快还是走路快。*//*#includeusing namespace std;int main(){ double s; cin>>s; double bs=s/1.2; double qs=s/3.0+23+27; if(bs { cout< } else if(bs>qs) { cout< } else { cout< } return 0;}*///给出一名学生的语文和数学成绩,//判断他是否恰好有一门课不及格(成绩小于60分)/*#includeusing namespace std;int main(){ int a,b; cin>>a>>b; if(a<60&&b>=60) { cout<<1; } else if(b<60&&a>=60) { cout<<1; } else { cout<<0; } return 0;}*///利用公式x1 = (-b + sqrt(b*b-4*a*c))/(2*a),//x2 = (-b - sqrt(b*b-4*a*c))/(2*a)//求一元二次方程ax2+ bx + c =0的根,其中a不等于0。/*#include#include#include#include using namespace std;int main(){ double a,b,c; cin>>a>>b>>c; double d=b*b-4*a*c; double der=sqrt(d); double x1=(-b+der)/(2*a); double x2=(-b-der)/(2*a); if(d==0) { cout<=x2="< } else if (d>0) { if (a>0) { cout << setprecision(5) << fixed << "x1=" << x1 << ";" << "x2=" << x2; } else { cout << setprecision(5) << fixed << "x2=" << x2 << ";" << "x1=" << x1; } } else { double m, n; double esp = pow(10, -7); m = -b / (2 * a) + esp; n = sqrt(-d) / (2 * a); printf("x1=%.5lf+%.5lfi;x2=%.5lf-%.5lfi\n", m, n, m, n); /*der = sqrt(-d); double x3 = -b / 2.0 / a; double x4 = der / 2.0 / a; if (b==0) { x3 = 0; } if (a>0) { cout << setprecision(5) << fixed << "x1=" << x3 << "+" << x4 << "i" << ";" << "x2=" << x3 << "-" << x4 << "i" << endl; } else { cout<fixed< }// } return 0;}*///虫子与苹果2/*#includeusing namespace std{ int n = 0, x = 0, y = 0; cin >> n >> x >> y; if (y <= n*x) { if (y%x == 0) { cout << n - y / x << endl; } else { cout << n - y / x - 1 << endl; } } else { cout << 0; } return 0;}*/
输入2个正整数lower和upper(lower_c++作业2
最新推荐文章于 2023-11-08 19:27:29 发布