2007/06/21 | 整理了一下遍历数组的简单基本方法,呵呵
类别(计算机与编程) | 评论(0) | 阅读(66) | 发表于 16:47

#include <iostream>
#include <string>
#include <vector>

using namespace std;

main()

{
 const int wangs_size = 18;
 int arrays_wangs [wangs_size];

 cout<<"wangs_size = "<<wangs_size<<endl;
 vector <int> arrays_kings (wangs_size);

 arrays_wangs [0] = 1;
 arrays_kings [0] = 00;
 arrays_wangs [1] = 2;
 arrays_kings [1] = 11;

 cout<<"arrays_wangs.[0] = "<<arrays_wangs [0]<<endl;
 cout<<"arrays_kings.[0] = "<<arrays_kings [0]<<endl;
 cout<<"arrays_wangs.[1] = "<<arrays_wangs [1]<<endl;
 cout<<"arrays_kings.[1] = "<<arrays_kings [1]<<endl;
 cout<<"====================================="<<endl;

 int x=2;

 for(;x<wangs_size;x++)
 {
  if (x==2) //the same mistake...GOD
  {
   cout<<"*arrays_wangs ["<<x-2<<"] = "<<arrays_wangs [0]<<" , "<<endl;
   cout<<"*arrays_wangs ["<<x-1<<"] = "<<arrays_wangs [1]<<" , "<<endl;
   arrays_wangs [x] = arrays_wangs [x-2] + 2 * arrays_wangs [x-1]; // pell array...
      cout<<"arrays_wangs ["<<x<<"] = "<<arrays_wangs [x]<<" , "<<endl;
  }
  else
  {
   arrays_wangs [x] = arrays_wangs [x-2] + 2 * arrays_wangs [x-1]; // pell array...
      cout<<"arrays_wangs ["<<x<<"] = "<<arrays_wangs [x]<<" , "<<endl;
  }  
 }

 return 0;
}

0

评论Comments

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