整理了一个有关IF用法的很好的C++代码,初学必看

      计算机与编程 2007-4-25 12:34:00

//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;
}

标签集:TAGS:
回复Comments() 点击Count()
喜欢就顶一下

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}