Thứ Năm, 21 tháng 1, 2016

BT8/B6/TR.24

#include &lt;conio.h&gt;<br />
#include &lt;stdio.h&gt;<br />
<br />
main()<br />
{<br />
<br />
&nbsp;//Trang tri chuong trinh<br />
&nbsp; int i;<br />
&nbsp; printf("\t");<br />
&nbsp; for (i=1;i&lt;30;i++) printf("* ");<br />
&nbsp; printf("\n\t\t CHUONG TRINH DAO NGUOC MOT MANG\n\n");<br />
&nbsp;//Het doan chuong trinh trang tri<br />
<br />
&nbsp; int n;<br />
<br />
&nbsp; printf("\t- Nhap vao so phan tu: "); scanf("%d",&amp;n);<br />
<br />
&nbsp; int a[n];<br />
<br />
&nbsp; printf("\n");<br />
<br />
&nbsp; for (i=1;i&lt;=n;i++)<br />
&nbsp; {<br />
&nbsp; &nbsp;printf("\t- Nhap vao phan tu a[%d]: ",i);<br />
&nbsp; &nbsp;scanf("%d",&amp;a[i]);<br />
&nbsp; &nbsp;}<br />
&nbsp; <br />
&nbsp; &nbsp;printf("\n\n");<br />
&nbsp; <br />
&nbsp; printf("\t=&gt; Mang ban da nhap: \n\t");<br />
&nbsp; &nbsp;for (i=1;i&lt;=n;i++)<br />
&nbsp; &nbsp;printf("%d &nbsp;",a[i]);<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp; &nbsp;printf("\n\n");<br />
<br />
&nbsp; printf("\t=&gt; Mang sau khi dao chieu: \n\t");<br />
&nbsp; <br />
&nbsp; int val;<br />
&nbsp; &nbsp;for (i=1;i&lt;=n/2;i++)<br />
&nbsp; {<br />
&nbsp; &nbsp;val=a[i];<br />
&nbsp; &nbsp;a[i]=a[n-i+1];<br />
&nbsp; &nbsp;a[n-i+1]=val; <br />
&nbsp; <br />
&nbsp; &nbsp;}<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; for (i=1;i&lt;=n;i++)<br />
&nbsp; &nbsp;printf("%d &nbsp;",a[i]);<br />
<br />
<br />
&nbsp;getch();<br />
&nbsp;return 0;<br />
}<

0 nhận xét: