kokokozhina

7

Dec 10th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream> //output first n members of sequence
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int number;
  8. double preprev = 4; //previous member to previous member
  9. double prev = -4; //previous member
  10. double current;
  11.  
  12. cout << "Enter the number of needed members = "; cin >> number;
  13.  
  14. if (number == 1)
  15. cout << endl << prev;
  16. else
  17. if (number == 2)
  18. cout << endl << preprev << endl << prev;
  19. else
  20. {
  21. cout << endl << preprev << endl << prev;
  22. for (int index = 3; index <= number; index++)
  23. {
  24. double swapper = preprev;
  25. current = 1.0 / 5.0 * (2 * preprev + 3 * prev);
  26. cout << endl << current;
  27. preprev = prev;
  28. prev = current;
  29.  
  30. }
  31. }
  32.  
  33. cout << endl;
  34. system("pause");
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment