1.#include<iostream.h>
void main()
{
int x,y;
cout<<"x=";cin>>x;
if(x>=1) y=x-1;
if(x<1) y=1-x;
cout<<"y="<<y<<endl;
void main()
{
int x,y;
cout<<"x=";cin>>x;
if(x>=1) y=x-1;
if(x<1) y=1-x;
cout<<"y="<<y<<endl;
}
2.#include<iostream.h>
#include<cmath>
void main()
{
int x1,y1,x2,y2,l;
cout<<"输入两点坐标"<<endl;
cout<<"x1=";cin>>x1;
cout<<"y1=";cin>>y1;
cout<<"x2=";cin>>x2;
cout<<"y2=";cin>>y2;
l=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
cout<<"两点之间距离为"<<sqrt(l)<<endl;
}
3.#include<iostream.h>
void main()
{
int a,b;
cout<<"工商银行欢迎你!"<<endl;
cout<<"请输入密码:"<<endl;
cin>>a;
if(a==233666)
{
cout<<"1.查询"<<endl<<"2.取款"<<endl<<"3.存款"<<endl<<"4.转账"<<endl<<"0.退出"<<endl;
cin>>b;
if(0<b&&b<=4) cout<<"谢谢,你选择了"<<b<<"号功能"<<endl;
if(b>=5) cout<<"你是不是傻"<<endl;
if(b==0) cout<<"谢谢"<<endl;
}
if(a!=233666) cout<<"密码错误"<<endl;
}
本文提供了三个C++程序实例:判断变量的正负并求值、计算两点间距离及模拟银行密码验证流程。通过这些实例,读者可以了解基本的输入输出操作、条件判断语句以及简单的数学计算。
248

被折叠的 条评论
为什么被折叠?



