Question: 5. What is the output of the following code?<div class="hk1_style-wrap4"><div class="hk1_style-wrap3"><div class="hk1_style-wrap2"><div class="hk1_style-wrap"><div class="hk1_style"><div class="c"><pre class="de1"><span class="co2">#include&lt;stdio.h&gt;</span> <span class="co2">#include&lt;stdlib.h&gt;</span> <span class="kw4">struct</span> Node <span class="br0">{</span> <span class="kw4">int</span> val<span class="sy0">;</span> <span class="kw4">struct</span> Node<span class="sy0">*</span> next<span class="sy0">;</span> <span class="br0">}</span><span class="sy0">*</span>head<span class="sy0">;</span> <span class="kw4">int</span> get_max<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span> <span class="kw4">struct</span> Node<span class="sy0">*</span> temp <span class="sy0">=</span> head<span class="sy0">-&gt;</span>next<span class="sy0">;</span> <span class="kw4">int</span> max_num <span class="sy0">=</span> temp<span class="sy0">-&gt;</span>val<span class="sy0">;</span> <span class="kw1">while</span><span class="br0">(</span>temp <span class="sy0">!=</span> <span class="nu0">0</span><span class="br0">)</span> <span class="br0">{</span> <span class="kw1">if</span><span class="br0">(</span>temp<span class="sy0">-&gt;</span>val <span class="sy0">&gt;</span> max_num<span class="br0">)</span> max_num <span class="sy0">=</span> temp<span class="sy0">-&gt;</span>val<span class="sy0">;</span> temp <span class="sy0">=</span> temp<span class="sy0">-&gt;</span>next<span class="sy0">;</span> <span class="br0">}</span> <span class="kw1">return</span> max_num<span class="sy0">;</span> <span class="br0">}</span> <span class="kw4">int</span> get_min<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span> <span class="kw4">struct</span> Node<span class="sy0">*</span> temp <span class="sy0">=</span> head<span class="sy0">-&gt;</span>next<span class="sy0">;</span> <span class="kw4">int</span> min_num <span class="sy0">=</span> temp<span class="sy0">-&gt;</span>val<span class="sy0">;</span> <span class="kw1">while</span><span class="br0">(</span>temp <span class="sy0">!=</span> <span class="nu0">0</span><span class="br0">)</span> <span class="br0">{</span> <span class="kw1">if</span><span class="br0">(</span>temp<span class="sy0">-&gt;</span>val <span class="sy0">&lt;</span> min_num<span class="br0">)</span> min_num <span class="sy0">=</span> temp<span class="sy0">-&gt;</span>val<span class="sy0">;</span> temp <span class="sy0">=</span> temp<span class="sy0">-&gt;</span>next<span class="sy0">;</span> <span class="br0">}</span> <span class="kw1">return</span> min_num<span class="sy0">;</span> <span class="br0">}</span> <span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span> <span class="kw4">int</span> i<span class="sy0">,</span> n <span class="sy0">=</span> <span class="nu0">9</span><span class="sy0">,</span> arr<span class="br0">[</span><span class="nu0">9</span><span class="br0">]</span> <span class="sy0">=</span><span class="br0">{</span><span class="nu0">8</span><span class="sy0">,</span><span class="nu0">3</span><span class="sy0">,</span><span class="nu0">3</span><span class="sy0">,</span><span class="nu0">4</span><span class="sy0">,</span><span class="nu0">5</span><span class="sy0">,</span><span class="nu0">2</span><span class="sy0">,</span><span class="nu0">5</span><span class="sy0">,</span><span class="nu0">6</span><span class="sy0">,</span><span class="nu0">7</span><span class="br0">}</span><span class="sy0">;</span> <span class="kw4">struct</span> Node <span class="sy0">*</span>temp<span class="sy0">,</span> <span class="sy0">*</span>newNode<span class="sy0">;</span> head <span class="sy0">=</span> <span class="br0">(</span><span class="kw4">struct</span> Node<span class="sy0">*</span><span class="br0">)</span><span class="kw3">malloc</span><span class="br0">(</span><span class="kw4">sizeof</span><span class="br0">(</span><span class="kw4">struct</span> Node<span class="br0">)</span><span class="br0">)</span><span class="sy0">;</span> head <span class="sy0">-&gt;</span> next <span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span> temp <span class="sy0">=</span> head<span class="sy0">;</span> <span class="kw1">for</span><span class="br0">(</span>i<span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span>i<span class="sy0">&lt;</span>n<span class="sy0">;</span>i<span class="sy0">++</span><span class="br0">)</span> <span class="br0">{</span> newNode <span class="sy0">=</span><span class="br0">(</span><span class="kw4">struct</span> Node<span class="sy0">*</span><span class="br0">)</span><span class="kw3">malloc</span><span class="br0">(</span><span class="kw4">sizeof</span><span class="br0">(</span><span class="kw4">struct</span> Node<span class="br0">)</span><span class="br0">)</span><span class="sy0">;</span> newNode<span class="sy0">-&gt;</span>next <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> newNode<span class="sy0">-&gt;</span>val <span class="sy0">=</span> arr<span class="br0">[</span>i<span class="br0">]</span><span class="sy0">;</span> temp<span class="sy0">-&gt;</span>next <span class="sy0">=</span>newNode<span class="sy0">;</span> temp <span class="sy0">=</span> temp<span class="sy0">-&gt;</span>next<span class="sy0">;</span> <span class="br0">}</span> <span class="kw4">int</span> max_num <span class="sy0">=</span> get_max<span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span> <span class="kw4">int</span> min_num <span class="sy0">=</span> get_min<span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span> <span class="kw3">printf</span><span class="br0">(</span><span class="st0">"%d %d"</span><span class="sy0">,</span>max_num<span class="sy0">,</span>min_num<span class="br0">)</span><span class="sy0">;</span> <span class="kw1">return</span> <span class="nu0">0</span><span class="sy0">;</span> <span class="br0">}</span></pre></div></div></div></div></div></div>
Options:
2 2
8 8
2 8
8 2
Answer: D