kiem tien, kiem tien online, kiem tien truc tuyen, kiem tien tren mang
Thứ Năm, 28 tháng 7, 2011

+ Ví dụ: n=3 ta có các dãy nhị phân như sau

Code:
0 0 0
0 0 1 
0 1 0 
0 1 1 
1 0 0 
1 0 1 
1 1 0 
1 1 1
+ Tác giả: CayDan

+ Code:

- Phương pháp sinh:


C Code:

void LKNhiPhan(int n)
{
int x[30];
for (int i=0; i x[i] = 0;
int i=n;
while (i>=0)
{
for (i=0; i printf("%d ",x[i]);
printf("\n");
i=n-1;
while ((i>=0) && (x[i] == 1)) i--;
if(i>=0)
{
x[i] = 1;
for (int j= i+1; j x[j] = 0;
}
}
}


- Phương pháp đệ qui:

C Code:

int x[30];
void Try(int i, int n)
{
for (int k=0; k<=1; k++)
{
x[i] = k;
if (i==n-1)
{
for (int j=0;j printf("%d ",x[j]);
printf("\n");
}
else Try(i+1, n);
}
}

void LKNhiPhan(int n)
{
Try(0, n);
}



28 Jul 2011

0 nhận xét:

Đăng nhận xét

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

domain, domain name, premium domain name for sales

Bài đăng phổ biến