fork download
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. double E, ak, ap, y=1;
  6. int i = 1, k=2 , p;
  7. p = k - 1;
  8. ap = 2;
  9. cout << "please, input E: ";
  10. cin >> E;
  11. ak = 2 + 1 / y;
  12.  
  13. if (E <= 0)
  14. {
  15. cout << "E<=0, mistake" << endl;
  16. }
  17. else
  18. {
  19. while (ak-ap<E)
  20. {
  21. k = 2;
  22. k++;
  23. double y = 1;
  24. int i = 1;
  25. while (i <= k)
  26. {
  27. y *= ap;
  28. i++;
  29. }
  30. ak = 2 + (1 / y);
  31. }
  32. cout << "output k=" << k << endl;
  33. cout << "output a(k-1)=" << ap << endl;
  34. cout << "output ak=" << ak << endl;
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 4192KB
stdin
Standard input is empty
stdout
please, input E: output k=2
output a(k-1)=2
output ak=3