2007/04/26 | 一个FOR语句头的初始化引起的一些问题
类别(计算机与编程) | 评论(0) | 阅读(10) | 发表于 12:43

//show all nums between any 2 nums...\

#include <iostream.h>

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

long int mid;
if (x>=y)
{
mid=x;
}
else
{
mid=x;x=y;y=mid;
}
//cout<<endl;
//cout<<"the big one is: "<<x<<endl;

cout<<endl;
long int z=y;
for (long int i=y;i<=x;++i) //该处是因该十分注意的地方,I初始化时一定要将其范围确定足够大。。。
{
//if (i%10=0)
//cout<<endl;
//else
cout<<"z= "<<z<<", ";
z=z+1;
if ((i-y+1)%10==0)
cout<<endl;
}

cout<<endl;
cout<<"the big one is: "<<x<<endl;

cout<<endl;
cout<<"have you seen the result?"<<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]