Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip> //for output formatting
- #include <fstream> //for file operations
- #include <cmath> //for maths functions
- using namespace std;
- //Define Function
- double function_18339286(int);
- int main()
- {
- int N;
- double y;
- //Question (b) i:
- //Ask user to enter value for N
- do {
- cout << "Enter a value for N (N must be an integer greater than 0): " << endl;
- cin >> N;
- } while (N < 0);
- //Part ii
- y=function_18339286(N);
- cout << "\nThe value of y is equal to ";
- cout << fixed << showpoint << setprecision(4) << y << endl;
- //Part iii
- ofstream output;
- output.open("function_output.txt");
- for (int N = 1; N <= 5; N++)
- {
- y = function_18339286(N);
- cout << "\nThe value of y is equal to ";
- cout << fixed << showpoint << setprecision(4) << y << endl;
- output << fixed << showpoint << setprecision(4) << y << endl;
- }
- output.close();
- system("pause");
- return (0);
- }
- double function_18339286(int N)
- {
- return (N+0.5)/(N^2+1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement