Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To answer some of your questions.</p> <p>1 My eclipse code does not blow up.</p> <p>2 I see no inherent inefficiency using for loops other than maybe too many iterations.</p> <p>3 Use <code>"%Le"</code> for scientific format.</p> <p>4 The maximum precision you can get will be about LDBL_EPSILON in 1. Depends on your system that I do not know (maybe 1 part in power(2,64)). Remember precision is relative, not absolute.</p> <p>5 Segmentation Fault likely due to <code>approx[5]</code>. @Grijesh Chauhan</p> <p>Suggestions</p> <p>Add <code>-15</code> to <code>long double x[13+1] = { 1, 5, 10, 15, 20, 50, 100, -1, -5, -10, -15, -20, -50, -100 };</code>. Change various other <code>13</code>s.</p> <p>Add return to error condition:<br> <code>if (n &lt; 0) { printf("Factorial is not defined for a negative number \n"); return 0; }</code></p> <p>Change to <code>long double approx[5+1+1] = { 0 };</code></p> <p>Add return to <code>main()</code>.</p> <p>You get better numeric results if you add the small terms up first. This usually means to reverse your <code>for (k = 0; k &lt;= p; k++)</code> loop.</p> <pre><code>int main() { long double x[13+1] = { 1, 5, 10, 15, 20, 50, 100, -1, -5, -10, -15, -20, -50, -100 }; int p = 150; long double series[13+1][p]; int i, k; long double sum[6+1] = { 0 }; for (i = 0; i &lt;= 6; i++) { for (k = 0; k &lt;= p; k++) { series[i][k] = pow(x[i], k) / (factorial(k)); sum[i] += series[i][k]; } printf("Approximation for x = %Le is %Le %e\n", x[i], sum[i], exp(x[i])); } long double approx[7] = { 0 }; for (i = 7; i &lt;= 12; i++) { approx[i - 7] = 1 / sum[i - 7]; printf("Approximation for x = %Le is %Le %e\n", x[i], approx[i - 7], exp(x[i])); } return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload