| 
| 
查看: 892|回复: 1
 | 
C++辨识prime number的source code,但不是很明白
[复制链接] |  
 |  | 
 
| #include <iostream>#include <vector>
 
 using namespace std;
 
 vector<int> getPrimes(int n)
 {
 vector<int> result;
 
 for (int i = 2; i <= n; i++)
 {
 bool isprime = true;
 for (int j = 0; j < result.size(); j++)
 {
 if (i % result[j] == 0)
 {
 isprime = false;
 break;
 }
 }
 if (isprime)
 result.push_back(i);
 
 }
 return result;
 }
 
 int main()
 {
 vector <int> primes = getPrimes(6);
 for (int i = 0; i < primes.size(); i++)
 {
 cout << primes << endl;
 }
 system("pause"
  ; }
 当中红色的字都不明白再说什么,如果可以的话,请各位帮忙解释一下。
  | 
 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 发表于 6-7-2006 06:49 AM
|
显示全部楼层 
| vector 是STL(Standard Template Language) 里的一个built-in template , 你需要找STL 的资料读读。 上google 找STL , 你会有收获的。
 | 
 |  |  |  |
 
|  |  |  
|  |  |  |  | 
            本周最热论坛帖子 |