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

BT 10/B4/TR22

#include&lt;stdio.h&gt;<br />
#include&lt;conio.h&gt;<br />
<br />
int tohop(int n,int k)<br />
{<br />
&nbsp;if (k==0||k==n)<br />
&nbsp; return 1;<br />
&nbsp;else<br />
&nbsp; return tohop(n-1,k-1)+tohop(n-1,k);<br />
}<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 TINH TO HOP chapKcuaN\n\n");<br />
&nbsp;//Het doan chuong trinh trang tri<br />
<br />
&nbsp;int a,b;<br />
&nbsp;do<br />
&nbsp;{<br />
&nbsp;printf("\n\t- Nhap n_k: "); scanf("%d %d",&amp;a,&amp;b);<br />
&nbsp;if (b&gt;a) printf("\t\t!! Ban nhap sai. k&lt;n &nbsp;!!\n");<br />
&nbsp; }<br />
&nbsp;while (a&lt;b);<br />
<br />
&nbsp;printf("\n\t=&gt;To hop chap %d cua %d = %d ",b,a,tohop(a,b));<br />
<br />
<br />
&nbsp; printf("\n\n\n\n\t\t\t\t http://tvlaptrinh.blogspot.com");<br />
&nbsp;getch();<br />
&nbsp;return 0;<br />
}<br />

0 nhận xét: