The $K$ in your formula is the largest possible absolute value of the second derivative of your function. So let $f(x)=x\cos x$. We calculate the second derivative of $f(x)$.
We have $f'(x)=-x\sin x+\cos x$. Differentiate again. We get
$$f''(x)=-x\cos x-\sin x-\sin x=-(2\sin x+x\cos x).$$
Now in principle, to find the best value of $K$, we should find the maximum of the absolute value of the second derivative. But we won't do that, it is too much trouble, and not really worth it.
So how big can the absolute value of the second derivative be? Let's be very pessimistic. The number $x$ could be as large as $\pi$. The absolute value of $\cos x$ and $\sin x$ is never bigger than $1$, so for sure the absolute value of the second derivative is $\le 2+\pi$. Thus, if we use $K=2+\pi$, we can be sure that we are taking a pessimistically large value for $K$.
Note that at $\pi$, the cosine is $-1$ and the sine is $0$, so the absolute value of the second derivative can be as large as $\pi$.
We can be less pessimistic. In the interval from $0$ to $\pi/2$, our second derivative is less than $2+\pi/2$. We can do better than that by looking at the second derivative in more detail, say between $0$ and $\pi/4$, and between $\pi/4$ and $\pi/2$.
In the interval from $\pi/2$ to $\pi$, the cosine is negative, while the sine is positive. The sine is definitely $\le 2$. The $x\cos x$ term is negative, so in the interval $[\pi/2,\pi]$, the absolute value of the derivative is less than or equal to the larger of $2$ and $\pi$, which is $\pi$.
So we have reduced our upper bound on the absolute value of the second derivative to $2+\pi/2$, say about $3.6$. We could do a bit better by graphing the second derivative on a graphing calculator, and eyeballing the largest absolute value.
It's not worth it. Use $K\le 3.6$ (or even $2+\pi$). Then we know that the error has absolute value which is less than or equal to
$$\frac{3.6\pi^3}{12n^2}.$$
We want to make sure that the above quantity is $\le 0.0001$. Equivalently, we want
$$n^2\ge \frac{3.6\pi^3}{(12)(0.0001}.$$
Finally, calculate. I get something like $n=305$.
Remark: There are many reasons not to work too hard to find the largest possible absolute value of the second derivative. If we are using numerical integration on $f$, it is probably because $f$ is at least a little unpleasant. Usually then, $f''$ will be more unpleasant still, and finding the maximum of its absolute value could be very difficult.
In addition, using the maximum of $|f''(x)|$ usually gives a needlessly pessimistic error estimate. I am certain that for the Trapezoidal Rule with your function, in reality we only need an $n$ much smaller than $305$ to get error $\le 0.0001$. The error estimate for the Trapezoidal Rule is close to the truth only for some really weird functions. For "nice" functions, the error bound you were given is unduly pessimistic.
The usual procedure is to calculate say $T_2$, $T_4$, $T_8$, and so on until successive answers change by less than one's error tolerance. This is theoretically not good enough, but works well in practice, particularly if you cross your fingers.
You have to find the upper bound of this error sum. Therefore you should take the maximum value of f'' on each subinterval (according to your formula). With $f(x)=\frac{1}{1+x}$, we got: $f''(x)=\frac{2}{(1+x)^3}$. The largest value of this function in the interval $[x_0,x_1]$ is $f''(x_0)$ , since $\ f''(x) \ $ is a decreasing function in [0,1]. For n=4, we got the intervals [0,0.25], [0.25,0.5] [0.5,0.75] [0.75,1] with corresponding maximum values for $f''(x)$ ,
$\ f''(0)=2, \ f''(0.25)=1.024, \ f''(0.5)=0.592 \ and \ f''(0.75)=0.373$. So an upper bound for your problem would be $\frac{h^3}{12} \sum_{i=1}^n |f^{''}(\xi_i)|=\frac{0.25^3}{12}(2+1.024+0.592+0.373)=0.005194$
Best Answer
A bound on the error in using Simpson's rule with $n$ subintervals to approximate the integral of $f(x)$ over $[a,b]$ is
$$E \leq \frac{(b-a)^5}{180n^4}\max_{a \leq x \leq b}|f^{iv}(x)|.$$
Differentiating $f(x) = 19e^{x^2}$ four times we have for $x \in [0,1]$
$$f^{iv}(x) = 19e^{x^2}(12+48x^2+16x^4) \leq 1444e.$$
We have $E < 0.0001$ if
$$ \frac{(b-a)^5}{180n^4}\max_{a \leq x \leq b}|f^{iv}(x)|= \frac{1444e}{180n^4}< 0.0001,$$
Thus $n \geq 22$ is required.