Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- void Question3() {
- float n, p, result = 0, num;
- cout << "Enter a positive integer for n: ";
- cin >> n;
- if (n == 1) {
- cout << "1";
- }
- else {
- for (int i = 2; i <= n; i++) {
- num = (float)i;
- p = ((num - (float)1) / num);
- result = result + p;
- //cout << p << endl;
- }
- result = result + 1;
- cout << result;
- }
- }
- void Question4() {
- float p, num;
- cin >> num;
- p = (num - 2.0) / (num - 1.0) + (num - 1.0) / num;
- cout << p;
- }
- int main()
- {
- Question3();
- //Question4();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement