Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. void Question3() {
  6. float n, p, result = 0, num;
  7.  
  8. cout << "Enter a positive integer for n: ";
  9. cin >> n;
  10.  
  11. if (n == 1) {
  12. cout << "1";
  13. }
  14.  
  15. else {
  16. for (int i = 2; i <= n; i++) {
  17. num = (float)i;
  18. p = ((num - (float)1) / num);
  19. result = result + p;
  20. //cout << p << endl;
  21. }
  22. result = result + 1;
  23. cout << result;
  24. }
  25. }
  26.  
  27. void Question4() {
  28. float p, num;
  29.  
  30. cin >> num;
  31.  
  32. p = (num - 2.0) / (num - 1.0) + (num - 1.0) / num;
  33.  
  34. cout << p;
  35. }
  36.  
  37. int main()
  38. {
  39. Question3();
  40. //Question4();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement