# GÓC SÁNG TẠO > Khu vực lập trình > C/C++ >  Bài toán 8 hậu

## loveseo

Code :


```

[COLOR=#000000][/COLOR][COLOR=#FF8000]/* Bai toan tam hoang hau */#include <stdio.h>[/COLOR][COLOR=#0000BB]int dong[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]8[/COLOR][COLOR=#007700]], [/COLOR][COLOR=#0000BB]cot[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]8[/COLOR][COLOR=#007700]], [/COLOR][COLOR=#0000BB]cheoxuoi[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]15[/COLOR][COLOR=#007700]], [/COLOR][COLOR=#0000BB]cheonguoc[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]15[/COLOR][COLOR=#007700]];[/COLOR][COLOR=#0000BB]void [/COLOR][COLOR=#007700]print (){  [/COLOR][COLOR=#0000BB]int i[/COLOR][COLOR=#007700];  [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]""[/COLOR][COLOR=#007700]);  for ([/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]<[/COLOR][COLOR=#0000BB]8[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]++)    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%3d"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]dong[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]]);}[/COLOR][COLOR=#0000BB]void thu[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]int i[/COLOR][COLOR=#007700]){  [/COLOR][COLOR=#0000BB]int j[/COLOR][COLOR=#007700];  for ([/COLOR][COLOR=#0000BB]j[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000BB]j[/COLOR][COLOR=#007700]<[/COLOR][COLOR=#0000BB]8[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000BB]j[/COLOR][COLOR=#007700]++)  {    if ([/COLOR][COLOR=#0000BB]cot[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]j[/COLOR][COLOR=#007700]] == [/COLOR][COLOR=#0000BB]1 [/COLOR][COLOR=#007700]&& [/COLOR][COLOR=#0000BB]cheoxuoi[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#0000BB]j[/COLOR][COLOR=#007700]] ==[/COLOR][COLOR=#0000BB]1 [/COLOR][COLOR=#007700]&& [/COLOR][COLOR=#0000BB]cheonguoc[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]-[/COLOR][COLOR=#0000BB]j[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#0000BB]7[/COLOR][COLOR=#007700]] == [/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700])    {      [/COLOR][COLOR=#0000BB]dong[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]j[/COLOR][COLOR=#007700];      [/COLOR][COLOR=#0000BB]cot[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]j[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700];      [/COLOR][COLOR=#0000BB]cheoxuoi[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#0000BB]j[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700];      [/COLOR][COLOR=#0000BB]cheonguoc[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]-[/COLOR][COLOR=#0000BB]j[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#0000BB]7[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700];      if ([/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]<[/COLOR][COLOR=#0000BB]7[/COLOR][COLOR=#007700])        [/COLOR][COLOR=#0000BB]thu[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700]);      else        print();      [/COLOR][COLOR=#0000BB]cot[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]j[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700];      [/COLOR][COLOR=#0000BB]cheoxuoi[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#0000BB]j[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700];      [/COLOR][COLOR=#0000BB]cheonguoc[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]-[/COLOR][COLOR=#0000BB]j[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#0000BB]7[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700];    }  }}[/COLOR][COLOR=#0000BB]void tim[/COLOR][COLOR=#007700](){   [/COLOR][COLOR=#0000BB]int i[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]q[/COLOR][COLOR=#007700];   for ([/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]<[/COLOR][COLOR=#0000BB]8[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]++)   {     [/COLOR][COLOR=#0000BB]cot[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700];     [/COLOR][COLOR=#0000BB]dong[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]] = -[/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700];   }   for ([/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]<[/COLOR][COLOR=#0000BB]15[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]++)   {     [/COLOR][COLOR=#0000BB]cheoxuoi[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700];     [/COLOR][COLOR=#0000BB]cheonguoc[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700];   }   [/COLOR][COLOR=#0000BB]thu[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700]);}[/COLOR][COLOR=#0000BB]void main[/COLOR][COLOR=#007700](){  [/COLOR][COLOR=#0000BB]tim[/COLOR][COLOR=#007700]();  [/COLOR][COLOR=#0000BB]getch[/COLOR][COLOR=#007700]();}[/COLOR] 



```

----------

