2013年11月18日 星期一

平方取中

#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
using namespace std;
int main(){
 int samplesToProduce,x;
 int newseed;
 vector<int> storage;
 cin >> x;
 cin >> samplesToProduce;
 x=x*x; 
 for (int i = 0; i < samplesToProduce; ++i)
 {
        //select the middle six digits for the next seed
  cout << setw(6);
  cout << x << "\t";
        newseed = (x / 10) % 1000;
  cout << setw(3);
  cout << newseed << endl;
  storage.push_back(newseed);        
        x = newseed * newseed;
 }
 system("pause");
}
/*
123 10
512
214
579
524
457
884
145
102
40
160
 
455 100
172 100
*/

沒有留言:

張貼留言