发觉论C的编译器的IDE还是MICROSOFT的比较好,以前练习用的BORLAND的真的不知道怎么熬过来的。
下面这个例子是针对IF,FOR,WHILE三种逻辑控制的综合运用,很简单,供初学者练习。代码的意义为输入任意两个数,程序会把两个数之间的整数从大到小,再从小到大分别打印到屏幕输出出来。
#include <iostream.h>
#include <string.h>
main()
{
cout<<endl;
cout<<"========================="<<endl;
cout<<"please input 2 nums: "<<endl;
//==
int from,to;
cout<<endl<<"please input the from.value: "<<endl;
cin>>from;
cout<<"please input the to.value: "<<endl;
cin>>to;
if (from>to)
{
int mid;
mid=from;
from=to;
to=mid;
}
cout<<endl;
cout<<"the big one is: "<<to<<endl;
cout<<"the small one is: "<<from<<endl;
int i;
for (i=from;i<=to;++i)
{
cout<<i<<", ";
}
while (i>=from)
{
cout<<i<<", ";
--i;
}
cout<<endl;
return 0;
}