关于C++的一些问题

来源:百度知道 编辑:UC知道 时间:2024/05/21 16:44:21
!.编写程序计算y的值
x-5 (x<1)
y={ x*5+2 (1<=x<10)
x+5 (x>=10)

第二题.从键盘上输入一个整数和一个浮点数,比较其大小并输出小值.

第一题:

#include<iostream>
using namespace std;
int main()
{
double x,y;
cout << "输入X:"<<endl;
cin>>x;
if (x<1) y = x-5;
if (1 <= x && x < 10) y = x*5+2;
if (x>=10) y = x + 5;
cout << "y的值为:" << y << endl;
return 0 ;
}
第二题:
#include<iostream>
using namespace std;
int main()
{
int a;
float b;
cin>>a;
cin>>b;
cout << (a > b ? b : a )<< endl;
return 0 ;
}

//第二题
#include<iostream>
using namespace std;
int main()
{
int a;
float b;
cin>>a>>b;
float temp;
temp=a;
if(temp<b)cout<<a;
else cout<<b;
return 0;
}

float y(float x)
{ if(x<1) y=x-5;
else if(x<10) y=x*5+2;
else y=x+5;
}