中午咨询了一个C++友人,同样的问题,算法改进如下

      计算机与编程 2007-4-26 16:38:00

/* another programme about the same thing...list nums between 2 nums...*/

#include <iostream.h>
#include <string.h>

main()
{
 cout << "====================" << endl;
 cout << "please input 2 nums:" << endl;
 int from, to;
 cout << endl << "please input the from.value: ";
 cin >> from;
 cout << endl;
 cout << "please input the to.value: ";
    cin >> to;
 cout << endl;
 cout << "====================" << endl;

 if (from > to)
    {
    int MID;
    MID=from;
    from=to;
    to=MID;
    } // 确保from <= to

 int line = 0; // 断行
 for (int i = from; i <= to; ++i)
    {
  cout << i << " ";
  if (++line % 10 == 0) cout << endl; // 十次一断行
 }

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

 return 0;

//this is a programme about list nums, aman designed.

}

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

回复Comments

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