Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Author: Aryan Surana
- //ID : 2018B4A70937H
- #include <bits/stdc++.h>
- using namespace std;
- float f(float x) {
- float result = 3*x - cos(x) - 1;
- return result;
- }
- int main() {
- float xl, xu, xm;
- cout << "Enter xl and xu: ";
- cin >> xl >> xu;
- char yn;
- do {
- cout << "Press y to start or n to exit: ";
- cin >> yn;
- float fxl = f(xl), fxu = f(xu), fxm = 0;
- xm = (xl + xu)/2;
- cout << "xm = " << xm;
- fxm = f(xm);
- cout << " f(xm) = " << fxm << "\n";
- if (fxm*fxl < 0) {
- xu = xm;
- continue;
- }
- else if (fxm*fxl > 0) {
- xl = xm;
- }
- }
- while (yn == 'y');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement