C++ Write a program for the following below.
Write a function fx(x) = x^3 + 2*x^2 + 3
call it in the main() and calculate values for x = 1.0, 2.0, 3.0, ..., 10.0
Also write a two column data.txt file with x and fx
#include <iostream> #include <fstream> #include <string> using namespace std; double f(double x) { return x*x*x + 2*x*x + 3; } int main() { ofstream out("data.txt"); out << "x\tfx" << endl; for (int x = 1; x <= 10; x++) { cout << x << "\t" << f(x) << endl; out << x << "\t" << f(x) << endl; } out.close(); return 0; }
Get Answers For Free
Most questions answered within 1 hours.