home *** CD-ROM | disk | FTP | other *** search
- // C++ program illustrates local variables in a function
-
- #include <iostream.h>
-
- double f(double x)
- {
- return x * x - 5 * x + 10;
- }
-
- double slope(double x)
- {
- double f1, f2, incrim = 0.01 * x;
- f1 = f(x + incrim);
- f2 = f(x - incrim);
- return (f1 - f2) / 2 / incrim;
- }
-
- main()
- {
- double x = 3.5;
-
- cout << "f(" << x << ") = " << f(x) << "\n"
- << "f'(" << x << ") = " << slope(x) << "\n";
-
- return 0;
- }