0
0 комментариев
<span class="co2">#include <iostream></span>
<span class="co2">#include <iomanip></span>
<span class="co2">#include <cmath></span>
<span class="kw2">using</span> <span class="kw2">namespace</span> std<span class="sy4">;</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw4">double</span> f, xstart, xend, dx, eps<span class="sy1">=</span><span class="nu16">0.00000000001</span><span class="sy4">;</span>
    
    <span class="kw3">cout</span> <span class="sy1"><<</span><span class="st0">"Enter xstart: "</span><span class="sy4">;</span> <span class="kw3">cin</span><span class="sy1">>></span>xstart<span class="sy4">;</span>
    <span class="kw3">cout</span> <span class="sy1"><<</span><span class="st0">"Enter xend: "</span><span class="sy4">;</span> <span class="kw3">cin</span><span class="sy1">>></span>xend<span class="sy4">;</span>
    <span class="kw3">cout</span> <span class="sy1"><<</span><span class="st0">"Enter dx: "</span><span class="sy4">;</span> <span class="kw3">cin</span><span class="sy1">>></span>dx<span class="sy4">;</span>
    
    <span class="kw3">cout</span> <span class="sy1"><<</span><span class="st0">"    TABL 1<span class="es1">\n</span>"</span><span class="sy1"><<</span><span class="st0">"    x"</span><span class="sy1"><<</span><span class="st0">"  "</span><span class="sy1"><<</span><span class="st0">"f(x)"</span><span class="sy1"><<</span>endl<span class="sy4">;</span>     
    <span class="kw1">for</span> <span class="br0">(</span><span class="kw4">double</span> i<span class="sy1">=</span>xstart<span class="sy4">;</span> i<span class="sy1"><=</span>xend<span class="sy4">;</span> i<span class="sy2">+</span><span class="sy1">=</span>dx<span class="br0">)</span> 
    <span class="br0">{</span>  
    <span class="kw1">if</span> <span class="br0">(</span>i<span class="sy1">>=</span><span class="sy2">-</span><span class="nu0">3</span> <span class="sy3">&&</span> i<span class="sy1"><=</span><span class="sy2">-</span><span class="nu0">2</span><span class="br0">)</span> f<span class="sy1">=</span><span class="sy2">-</span>i<span class="sy2">-</span><span class="nu0">2</span><span class="sy4">;</span>
    <span class="kw1">if</span> <span class="br0">(</span>i<span class="sy1">></span><span class="sy2">-</span><span class="nu0">2</span> <span class="sy3">&&</span> i<span class="sy1"><</span><span class="sy2">-</span><span class="nu0">1</span><span class="br0">)</span> f<span class="sy1">=</span><span class="kw3">sqrt</span><span class="br0">(</span><span class="nu0">1</span><span class="sy2">-</span><span class="br0">(</span>i<span class="sy2">+</span><span class="nu0">1</span><span class="br0">)</span><span class="sy2">*</span><span class="br0">(</span>i<span class="sy2">+</span><span class="nu0">1</span><span class="br0">)</span><span class="br0">)</span><span class="sy4">;</span>
    <span class="kw1">if</span> <span class="br0">(</span>i<span class="sy1">>=</span><span class="sy2">-</span><span class="nu0">1</span> <span class="sy3">&&</span> i<span class="sy1"><=</span><span class="nu0">1</span><span class="br0">)</span> f<span class="sy1">=</span><span class="nu0">1</span><span class="sy4">;</span>
    <span class="kw1">if</span> <span class="br0">(</span>i<span class="sy1">></span><span class="nu0">1</span> <span class="sy3">&&</span> i<span class="sy1"><</span><span class="nu0">2</span><span class="br0">)</span> f<span class="sy1">=</span><span class="sy2">-</span><span class="nu0">2</span><span class="sy2">*</span>i<span class="sy2">+</span><span class="nu0">3</span><span class="sy4">;</span>
    <span class="kw1">if</span> <span class="br0">(</span>i<span class="sy1">>=</span><span class="nu0">2</span> <span class="sy3">&&</span> i <span class="sy1"><=</span><span class="nu0">5</span><span class="br0">)</span> f<span class="sy1">=</span><span class="sy2">-</span><span class="nu0">1</span><span class="sy4">;</span> 
 
    <span class="kw1">if</span> <span class="br0">(</span><span class="br0">(</span>i<span class="sy1">></span><span class="sy2">-</span><span class="nu0">2</span><span class="sy2">-</span>eps<span class="sy3">&&</span>i<span class="sy1"><</span><span class="sy2">-</span><span class="nu0">2</span><span class="sy2">+</span>eps<span class="br0">)</span><span class="sy3">||</span><span class="br0">(</span>i<span class="sy1">></span><span class="nu16">1.5</span><span class="sy2">-</span>eps<span class="sy3">&&</span>i<span class="sy1"><</span><span class="nu16">1.5</span><span class="sy2">+</span>eps<span class="br0">)</span><span class="br0">)</span> <span class="kw3">cout</span><span class="sy1"><<</span>setw<span class="br0">(</span><span class="nu0">6</span><span class="br0">)</span><span class="sy1"><<</span>i<span class="sy1"><<</span><span class="st0">" "</span><span class="sy1"><<</span><span class="nu0">0</span><span class="sy1"><<</span>endl<span class="sy4">;</span>
    <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">(</span>i<span class="sy1">></span><span class="sy2">-</span>eps<span class="sy3">&&</span>i<span class="sy1"><</span>eps<span class="br0">)</span> <span class="kw3">cout</span><span class="sy1"><<</span>setw<span class="br0">(</span><span class="nu0">6</span><span class="br0">)</span><span class="sy1"><<</span><span class="nu0">0</span><span class="sy1"><<</span><span class="st0">" "</span><span class="sy1"><<</span>f<span class="sy1"><<</span>endl<span class="sy4">;</span>
    <span class="kw1">else</span> <span class="kw3">cout</span><span class="sy1"><<</span>setw<span class="br0">(</span><span class="nu0">6</span><span class="br0">)</span><span class="sy1"><<</span>i<span class="sy1"><<</span><span class="st0">" "</span><span class="sy1"><<</span>f<span class="sy1"><<</span>endl<span class="sy4">;</span>    
    <span class="br0">}</span>     
<span class="kw3">system</span><span class="br0">(</span><span class="st0">"pause"</span><span class="br0">)</span><span class="sy4">;</span>
<span class="kw1">return</span> <span class="nu0">0</span><span class="sy4">;</span>
<span class="br0">}</span>
Решенный вопрос
Добавить комментарий