上机作业2-2,3,4

来源:互联网 发布:网络禁书100本百度云 编辑:程序博客网 时间:2024/04/27 12:32
2分段函数

#include<iostream>using namespace std;int main(){    double x,y;    cin>>x;    if(x>=1)        {            y=x-1;            cout<<y;        }    else    {        y=1-x;        cout<<y;    }return 0;
3两点距离
# include<iostream># include<cmath>using namespace std;int main(){ double x1,x2,y1,y2,a,b,c; cin>>x1>>x2>>y1>>y2; a=(x1-x2)*(x1-x2); b=(y1-y2)*(y1-y2); c=sqrt(a+b); cout<<c<<endl;}

4自动取款机

# include<iostream>
using namespace std;
int main()
{
    int x,z;
    const int y=199710;
    cin>>x;
    if(x==y)
    {
        cout<<"1.查询\n"<<"2.取款\n"<<"3.存款\n"<<"4.转账\n"<<"0.退出\n";
        cin>>z;
        cout<<"谢谢,"<<"你选择了" <<z<<"号功能";
    }
    else
        cout<<"密码错误";
    return 0;

}


0 0
原创粉丝点击