Posted By

brm on 01/03/16


Tagged

test


Versions (?)

Sequence Generate


 / Published in: C++
 

c++ generate sequence pow 2

  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. double power_two();
  8.  
  9. int main() {
  10. vector<double> x(5);
  11. //generating
  12. generate(x.begin(), x.end(), power_two);
  13. cout << "POW 2: ";
  14. for(unsigned n=0; n < x.size(); ++n)
  15. cout << x[n] << " - ";
  16. return 0;
  17. }
  18.  
  19. double power_two() {
  20. static double res = 1.0;
  21. double i;
  22. i = res;
  23. res += res;;
  24. return i;
  25. }

Report this snippet  

You need to login to post a comment.