Re: [問題] 複數&亂數的矩陣

看板C_and_CPP作者 (非天夜翔)時間16年前 (2009/06/13 06:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/4 (看更多)
※ 引述《chrisdar (克里斯)》之銘言: : #include <iostream> : #include <ctime> : #include <complex> : #include <vector> : #include <algorithm> : using namespace std; : typedef complex<double> complex_t; : typedef vector<complex<double>> complex_ct; : inline complex_t rand_complex(void) { : return complex_t(rand(), rand() / (RAND_MAX + 1.0)); : } : int main(int argc, char* argv[]) { : srand((unsigned int)time(0)); : complex_ct data; : generate_n(back_inserter(data), 15, rand_complex); : copy(data.begin(), data.end(), ostream_iterator<complex_t>(cout, "\n")); : system("pause"); : return 0; : } : P幣 Get!! 真是高招阿 QQ" 學起來~謝謝 m(_@_)m 提供我想的 #include <ctime> #include <complex> #include <iostream> typedef complex<double> dComplex; inline dComplex* randDComplex() { return new dComplex(rand(),rand()/(RAND_MAX+1.0)); } int main(int argc, char *argv[]) { dComplex** = new dComplex[10]; for(int i = 0; i < 10; i++) { dComplex[i] = randDComplex(); cout << "d[" << i << "] = (" << dComplex[i]->real() << ")+(" << dComplex[i]->imag() << ")" << endl; } system("pause"); return 0; } 常會把 java 和 C++ 的 coding 弄混Q.Q" 有錯還請大大指正 m(_@_)m -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.74.9.2
文章代碼(AID): #1ACqW7pO (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1ACqW7pO (C_and_CPP)