2007/04/25 | 整理了一个有关IF用法的很好的C++代码,初学必看
类别(计算机与编程) | 评论(0) | 阅读(41) | 发表于 12:34

//2002.09.01.this is my first programme about if...

#include <iostream.h>

main()
{
cout<<"================================="<<endl;
cout<<"please input 2 nums, any 2 nums: "<<endl;
long int x,y;
cout<<"please input the x:"<<endl;
cin>>x;
cout<<"please input the y:"<<endl;
cin>>y;

long int lower,upper;
if (x<=y)
{
lower=x;
upper=y;
}
else
{
upper=x;
lower=y;
};

long int sum=0;
for (int i=lower;i<=upper;++i)
cout<<"i= "<<i<<",";
sum=sum+i;
cout<<endl;

cout<<"the x is: "<<x<<endl;
cout<<"the y is: "<<y<<endl;
cout<<"the lower is: "<<lower<<endl;
cout<<"the upper is: "<<upper<<endl;
cout<<"the sum is: "<<sum<<endl;
cout<<"the i is: "<<i<<endl;

cout<<"do you want to exit?"<<endl;
char BB;
cin>>BB;
return 0;
}

0

评论Comments

日志分类
首页[666]
计算机与编程[133]
EMU[40]
UFOs[24]
房产[127]
音乐[13]
LOG[0]
经济[120]
影视[3]
物理[7]
数学[8]
社会[105]
职场[9]
生物医学[18]
生活[59]