Sequence Generate


/ Published in: C++
Save to your folder(s)

c++ generate sequence pow 2


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.