Re: [問題] 複數&亂數的矩陣
※ 引述《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
討論串 (同標題文章)