title: How to ask the user to input a mathematical function in c language?
body: <p>I am doing a university project where I have to create a numerical integration calculator. I need the user to input the integrand function to replace the <code>double f(double x)</code> function below so that my program can work for any 1-D integral with non-infinity limits.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;math.h&gt;
  
  double f(double x)
  {
      return x;
  }
  
  double traprule(double a, double b, double N)
  {
      double h, sum, fn, fa, fb, I;
  
      sum = 0;
      h = (b - a) / N;
  
      for (int n = 1; n &lt; N; n++)
      {
          fn = f(a + n * h);
          sum = sum + fn;
      }
  
      fa = f(a);
      fb = f(b);
      I = 0.5 * h * ((fa + fb) + 2 * sum);
      return I;
  }
  
  int main()
  {
      scanf("%s", &amp;f)
      double result;
      result = traprule(0, 10, 10);
      printf("%lg", result);
      return 0;
  }
  </code></pre>