diff --git a/Bai057/Source.cpp b/Bai057/Source.cpp index 9e1927f..2b35f35 100644 --- a/Bai057/Source.cpp +++ b/Bai057/Source.cpp @@ -1,8 +1,34 @@ #include +#include +#include using namespace std; +float Tinh(float, int); + int main() { + int n; + float x; + cout << "Nhap x: "; + cin >> x; + cout << "Nhap n: "; + cin >> n; + cout << "\nKet qua cua S(" << n << ") la: " << setw(5) << Tinh(x, n) << endl; return 0; +} + +float Tinh(float x, int n) +{ + if (n == 0) + { + return 0; + } + if (n == 1) + { + return x; + } + float a = Tinh(x, n - 1); + float b = Tinh(x, n - 2); + return ((1 + x/n) * a - x/n * b); } \ No newline at end of file diff --git a/Bai062/Source.cpp b/Bai062/Source.cpp index 9e1927f..22cd72c 100644 --- a/Bai062/Source.cpp +++ b/Bai062/Source.cpp @@ -1,8 +1,86 @@ -#include -using namespace std; +#include +#include + +void merge(int arr[], int l, int m, int r) +{ + int i, j, k; + int n1 = m - l + 1; + int n2 = r - m; + + int L[1000], R[1000]; + + for (i = 0; i < n1; i++) + L[i] = arr[l + i]; + for (j = 0; j < n2; j++) + R[j] = arr[m + 1 + j]; + + i = 0; + j = 0; + k = l; + while (i < n1 && j < n2) + { + if (L[i] <= R[j]) + { + arr[k] = L[i]; + i++; + } + else + { + arr[k] = R[j]; + j++; + } + k++; + } + + while (i < n1) + { + arr[k] = L[i]; + i++; + k++; + } + + while (j < n2) + { + arr[k] = R[j]; + j++; + k++; + } +} + +void mergeSort(int arr[], int l, int r) +{ + if (l < r) + { + int m = l + (r - l) / 2; + + mergeSort(arr, l, m); + mergeSort(arr, m + 1, r); + + merge(arr, l, m, r); + } +} + + +void printArray(int A[], int size) +{ + int i; + for (i = 0; i < size; i++) + printf("%d ", A[i]); + printf("\n"); +} + int main() { + int arr[] = { 12, 11, 13, 5, 6, 7 }; + int arr_size = sizeof(arr) / sizeof(arr[0]); + + printf("Given array is \n"); + printArray(arr, arr_size); + + mergeSort(arr, 0, arr_size - 1); - return 0; + printf("\nSorted array is \n"); + printArray(arr, arr_size); + return 0; } \ No newline at end of file diff --git a/Bai067/Source.cpp b/Bai067/Source.cpp index 9e1927f..67168eb 100644 --- a/Bai067/Source.cpp +++ b/Bai067/Source.cpp @@ -1,8 +1,42 @@ #include +#include + using namespace std; -int main() -{ +void generate_permutations(vector& seq, vector& curr_perm, vector& used) { + if (curr_perm.size() == seq.size()) { + for (int i = 0; i < curr_perm.size(); i++) { + cout << curr_perm[i] << " "; + } + cout << endl; + return; + } + + for (int i = 0; i < seq.size(); i++) { + if (!used[i]) { + used[i] = true; + curr_perm.push_back(seq[i]); + generate_permutations(seq, curr_perm, used); + used[i] = false; + curr_perm.pop_back(); + } + } +} + +int main() { + vector seq; + int n; + cout << "Enter number of elements: "; + cin >> n; + cout << "Enter elements: "; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + seq.push_back(x); + } + vector curr_perm; + vector used(n, false); + generate_permutations(seq, curr_perm, used); - return 0; -} \ No newline at end of file + return 0; +} diff --git a/Bai072/Source.cpp b/Bai072/Source.cpp index 9e1927f..39e7aee 100644 --- a/Bai072/Source.cpp +++ b/Bai072/Source.cpp @@ -1,8 +1,41 @@ #include +#include +#include + using namespace std; +void Nhap(float[], int&); +void LietKe(float[], int); + int main() { - + float a[100]; + int n; + Nhap(a, n); + LietKe(a, n); return 0; +} + +void Nhap(float a[], int& n) +{ + cout << "Nhap n: "; + cin >> n; + cout << "Nhap mang: "; + srand(time(NULL)); + for (int i = 0; i < n; i++) + a[i] = rand() % 201 - 100.00; + cout << "\nMang ban dau la: "; + for (int i = 0; i < n; i++) + cout << setw(5) << a[i]; + cout << endl; + cout << "Cac so duong trong mang la: "; +} + +void LietKe(float a[], int n) +{ + if (n == 0) + return; + LietKe(a, n - 1); + if (a[n - 1] > 0) + cout << setw(10) << setprecision(3) << a[n - 1]; } \ No newline at end of file diff --git a/Bai077/Source.cpp b/Bai077/Source.cpp index 9e1927f..aafae83 100644 --- a/Bai077/Source.cpp +++ b/Bai077/Source.cpp @@ -1,8 +1,41 @@ #include +#include +#include + using namespace std; +void Nhap(float[], int&); +void LietKe(float[], int); + int main() { - + float a[100]; + int n; + Nhap(a, n); + LietKe(a, n); return 0; +} + +void Nhap(float a[], int& n) +{ + cout << "Nhap n: "; + cin >> n; + cout << "Nhap mang: "; + srand(time(NULL)); + for (int i = 0; i < n; i++) + a[i] = rand() % 201 - 100.00; + cout << "\nMang ban dau la: "; + for (int i = 0; i < n; i++) + cout << setw(5) << a[i]; + cout << endl; + cout << "Cac vi tri am trong mang la: "; +} + +void LietKe(float a[], int n) +{ + if (n == 0) + return; + LietKe(a, n - 1); + if (a[n - 1] < 0) + cout << setw(10) << n-1; } \ No newline at end of file diff --git a/Bai082/Source.cpp b/Bai082/Source.cpp index 9e1927f..ccc49d7 100644 --- a/Bai082/Source.cpp +++ b/Bai082/Source.cpp @@ -1,8 +1,60 @@ #include +#include +#include + using namespace std; +void Nhap(float[], int&); +void LietKe(float[], int); +float LonNhat(float[], int); + int main() { - + float a[100]; + int n; + Nhap(a, n); + LietKe(a, n); return 0; +} + +void Nhap(float a[], int& n) +{ + cout << "Nhap n: "; + cin >> n; + cout << "Nhap mang: "; + srand(time(NULL)); + for (int i = 0; i < n; i++) + cin >> a[i]; + cout << "\nMang ban dau la: "; + for (int i = 0; i < n; i++) + cout << setw(5) << a[i]; + cout << endl; + cout << "Cac vi tri tai do la gia tri lon nhat la: "; +} + +void LietKe(float a[], int n) +{ + if (n == 0) + return; + float lc = LonNhat(a, n - 1); + if (lc < a[n - 1]) + { + cout << setw(6) << n - 1; + return; + } + if (lc == a[n - 1]) + cout << setw(6) << n - 1; + LietKe(a, n - 1); + +} + +float LonNhat(float a[], int n) +{ + if (n == 1) + return a[0]; + float lc=LonNhat(a, n - 1); + if (a[n - 1] >= lc) + lc = a[n - 1]; + return lc; + } \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index b896843..783da29 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,7 +13,7 @@ [![GitHub contributors](https://img.shields.io/github/contributors/NMLT-NTTMK-K18/6-290-recursion?style=for-the-badge&color=FBF0B2)](../../../graphs/contributors) [![CodeFactor](https://img.shields.io/codefactor/grade/github/nmlt-nttmk-k18/6-290-recursion?style=for-the-badge)](https://www.codefactor.io/repository/github/nmlt-nttmk-k18/6-290-recursion) -[![WorkedProject Badge](https://img.shields.io/badge/progress-115%20%2F%20290-82A0D8?style=for-the-badge)](./UnworkedProject.md) +[![WorkedProject Badge](https://img.shields.io/badge/progress-133%20%2F%20290-82A0D8?style=for-the-badge)](./UnworkedProject.md) [![RAR Source](https://img.shields.io/badge/rar_source-download-FF8080?style=for-the-badge)](../../../releases/download/RAR/23520161_23520730_23520623_23521049_23521734_BT06.rar/) [![TXT Github Link](https://img.shields.io/badge/txt_github_link-download-8CB369?style=for-the-badge)](../../../releases/download/RAR/23520161_23520730_23520623_23521049_23521734_BT06.txt/) diff --git a/docs/UnworkedProject.md b/docs/UnworkedProject.md index f8e96e2..fd993d2 100644 --- a/docs/UnworkedProject.md +++ b/docs/UnworkedProject.md @@ -25,156 +25,138 @@ List các file `Source.cpp` chưa làm: 20. [Bai050](../Bai050/Source.cpp) 21. [Bai054](../Bai054/Source.cpp) 22. [Bai055](../Bai055/Source.cpp) -23. [Bai057](../Bai057/Source.cpp) -24. [Bai059](../Bai059/Source.cpp) -25. [Bai060](../Bai060/Source.cpp) -26. [Bai062](../Bai062/Source.cpp) -27. [Bai064](../Bai064/Source.cpp) -28. [Bai065](../Bai065/Source.cpp) -29. [Bai067](../Bai067/Source.cpp) -30. [Bai069](../Bai069/Source.cpp) -31. [Bai070](../Bai070/Source.cpp) -32. [Bai072](../Bai072/Source.cpp) -33. [Bai074](../Bai074/Source.cpp) -34. [Bai075](../Bai075/Source.cpp) -35. [Bai077](../Bai077/Source.cpp) -36. [Bai079](../Bai079/Source.cpp) -37. [Bai080](../Bai080/Source.cpp) -38. [Bai082](../Bai082/Source.cpp) -39. [Bai084](../Bai084/Source.cpp) -40. [Bai085](../Bai085/Source.cpp) -41. [Bai087](../Bai087/Source.cpp) -42. [Bai089](../Bai089/Source.cpp) -43. [Bai090](../Bai090/Source.cpp) -44. [Bai092](../Bai092/Source.cpp) -45. [Bai094](../Bai094/Source.cpp) -46. [Bai095](../Bai095/Source.cpp) -47. [Bai097](../Bai097/Source.cpp) -48. [Bai099](../Bai099/Source.cpp) -49. [Bai100](../Bai100/Source.cpp) -50. [Bai102](../Bai102/Source.cpp) -51. [Bai104](../Bai104/Source.cpp) -52. [Bai105](../Bai105/Source.cpp) -53. [Bai107](../Bai107/Source.cpp) -54. [Bai109](../Bai109/Source.cpp) -55. [Bai110](../Bai110/Source.cpp) -56. [Bai112](../Bai112/Source.cpp) -57. [Bai114](../Bai114/Source.cpp) -58. [Bai115](../Bai115/Source.cpp) -59. [Bai117](../Bai117/Source.cpp) -60. [Bai119](../Bai119/Source.cpp) -61. [Bai120](../Bai120/Source.cpp) -62. [Bai122](../Bai122/Source.cpp) -63. [Bai124](../Bai124/Source.cpp) -64. [Bai125](../Bai125/Source.cpp) -65. [Bai127](../Bai127/Source.cpp) -66. [Bai129](../Bai129/Source.cpp) -67. [Bai130](../Bai130/Source.cpp) -68. [Bai132](../Bai132/Source.cpp) -69. [Bai134](../Bai134/Source.cpp) -70. [Bai135](../Bai135/Source.cpp) -71. [Bai137](../Bai137/Source.cpp) -72. [Bai139](../Bai139/Source.cpp) -73. [Bai140](../Bai140/Source.cpp) -74. [Bai142](../Bai142/Source.cpp) -75. [Bai144](../Bai144/Source.cpp) -76. [Bai145](../Bai145/Source.cpp) -77. [Bai147](../Bai147/Source.cpp) -78. [Bai149](../Bai149/Source.cpp) -79. [Bai150](../Bai150/Source.cpp) -80. [Bai152](../Bai152/Source.cpp) -81. [Bai154](../Bai154/Source.cpp) -82. [Bai155](../Bai155/Source.cpp) -83. [Bai157](../Bai157/Source.cpp) -84. [Bai159](../Bai159/Source.cpp) -85. [Bai160](../Bai160/Source.cpp) -86. [Bai162](../Bai162/Source.cpp) -87. [Bai164](../Bai164/Source.cpp) -88. [Bai165](../Bai165/Source.cpp) -89. [Bai167](../Bai167/Source.cpp) -90. [Bai169](../Bai169/Source.cpp) -91. [Bai170](../Bai170/Source.cpp) -92. [Bai172](../Bai172/Source.cpp) -93. [Bai174](../Bai174/Source.cpp) -94. [Bai175](../Bai175/Source.cpp) -95. [Bai177](../Bai177/Source.cpp) -96. [Bai179](../Bai179/Source.cpp) -97. [Bai180](../Bai180/Source.cpp) -98. [Bai181](../Bai181/Source.cpp) -99. [Bai182](../Bai182/Source.cpp) -100. [Bai184](../Bai184/Source.cpp) -101. [Bai185](../Bai185/Source.cpp) -102. [Bai187](../Bai187/Source.cpp) -103. [Bai189](../Bai189/Source.cpp) -104. [Bai190](../Bai190/Source.cpp) -105. [Bai192](../Bai192/Source.cpp) -106. [Bai194](../Bai194/Source.cpp) -107. [Bai195](../Bai195/Source.cpp) -108. [Bai197](../Bai197/Source.cpp) -109. [Bai199](../Bai199/Source.cpp) -110. [Bai200](../Bai200/Source.cpp) -111. [Bai202](../Bai202/Source.cpp) -112. [Bai204](../Bai204/Source.cpp) -113. [Bai205](../Bai205/Source.cpp) -114. [Bai207](../Bai207/Source.cpp) -115. [Bai209](../Bai209/Source.cpp) -116. [Bai210](../Bai210/Source.cpp) -117. [Bai212](../Bai212/Source.cpp) -118. [Bai214](../Bai214/Source.cpp) -119. [Bai215](../Bai215/Source.cpp) -120. [Bai217](../Bai217/Source.cpp) -121. [Bai219](../Bai219/Source.cpp) -122. [Bai220](../Bai220/Source.cpp) -123. [Bai222](../Bai222/Source.cpp) -124. [Bai224](../Bai224/Source.cpp) -125. [Bai225](../Bai225/Source.cpp) -126. [Bai227](../Bai227/Source.cpp) -127. [Bai229](../Bai229/Source.cpp) -128. [Bai230](../Bai230/Source.cpp) -129. [Bai232](../Bai232/Source.cpp) -130. [Bai234](../Bai234/Source.cpp) -131. [Bai235](../Bai235/Source.cpp) -132. [Bai236](../Bai236/Source.cpp) -133. [Bai237](../Bai237/Source.cpp) -134. [Bai239](../Bai239/Source.cpp) -135. [Bai240](../Bai240/Source.cpp) -136. [Bai241](../Bai241/Source.cpp) -137. [Bai242](../Bai242/Source.cpp) -138. [Bai244](../Bai244/Source.cpp) -139. [Bai245](../Bai245/Source.cpp) -140. [Bai246](../Bai246/Source.cpp) -141. [Bai247](../Bai247/Source.cpp) -142. [Bai249](../Bai249/Source.cpp) -143. [Bai250](../Bai250/Source.cpp) -144. [Bai251](../Bai251/Source.cpp) -145. [Bai252](../Bai252/Source.cpp) -146. [Bai254](../Bai254/Source.cpp) -147. [Bai255](../Bai255/Source.cpp) -148. [Bai256](../Bai256/Source.cpp) -149. [Bai257](../Bai257/Source.cpp) -150. [Bai259](../Bai259/Source.cpp) -151. [Bai260](../Bai260/Source.cpp) -152. [Bai261](../Bai261/Source.cpp) -153. [Bai262](../Bai262/Source.cpp) -154. [Bai264](../Bai264/Source.cpp) -155. [Bai265](../Bai265/Source.cpp) -156. [Bai266](../Bai266/Source.cpp) -157. [Bai267](../Bai267/Source.cpp) -158. [Bai269](../Bai269/Source.cpp) -159. [Bai270](../Bai270/Source.cpp) -160. [Bai271](../Bai271/Source.cpp) -161. [Bai272](../Bai272/Source.cpp) -162. [Bai274](../Bai274/Source.cpp) -163. [Bai275](../Bai275/Source.cpp) -164. [Bai276](../Bai276/Source.cpp) -165. [Bai277](../Bai277/Source.cpp) -166. [Bai279](../Bai279/Source.cpp) -167. [Bai280](../Bai280/Source.cpp) -168. [Bai281](../Bai281/Source.cpp) -169. [Bai282](../Bai282/Source.cpp) -170. [Bai284](../Bai284/Source.cpp) -171. [Bai285](../Bai285/Source.cpp) -172. [Bai286](../Bai286/Source.cpp) -173. [Bai287](../Bai287/Source.cpp) -174. [Bai289](../Bai289/Source.cpp) -175. [Bai290](../Bai290/Source.cpp) +23. [Bai059](../Bai059/Source.cpp) +24. [Bai060](../Bai060/Source.cpp) +25. [Bai064](../Bai064/Source.cpp) +26. [Bai065](../Bai065/Source.cpp) +27. [Bai069](../Bai069/Source.cpp) +28. [Bai070](../Bai070/Source.cpp) +29. [Bai074](../Bai074/Source.cpp) +30. [Bai075](../Bai075/Source.cpp) +31. [Bai079](../Bai079/Source.cpp) +32. [Bai080](../Bai080/Source.cpp) +33. [Bai084](../Bai084/Source.cpp) +34. [Bai085](../Bai085/Source.cpp) +35. [Bai087](../Bai087/Source.cpp) +36. [Bai089](../Bai089/Source.cpp) +37. [Bai090](../Bai090/Source.cpp) +38. [Bai092](../Bai092/Source.cpp) +39. [Bai094](../Bai094/Source.cpp) +40. [Bai095](../Bai095/Source.cpp) +41. [Bai097](../Bai097/Source.cpp) +42. [Bai099](../Bai099/Source.cpp) +43. [Bai100](../Bai100/Source.cpp) +44. [Bai102](../Bai102/Source.cpp) +45. [Bai104](../Bai104/Source.cpp) +46. [Bai105](../Bai105/Source.cpp) +47. [Bai107](../Bai107/Source.cpp) +48. [Bai109](../Bai109/Source.cpp) +49. [Bai110](../Bai110/Source.cpp) +50. [Bai112](../Bai112/Source.cpp) +51. [Bai114](../Bai114/Source.cpp) +52. [Bai115](../Bai115/Source.cpp) +53. [Bai117](../Bai117/Source.cpp) +54. [Bai119](../Bai119/Source.cpp) +55. [Bai120](../Bai120/Source.cpp) +56. [Bai122](../Bai122/Source.cpp) +57. [Bai124](../Bai124/Source.cpp) +58. [Bai125](../Bai125/Source.cpp) +59. [Bai127](../Bai127/Source.cpp) +60. [Bai129](../Bai129/Source.cpp) +61. [Bai130](../Bai130/Source.cpp) +62. [Bai132](../Bai132/Source.cpp) +63. [Bai134](../Bai134/Source.cpp) +64. [Bai135](../Bai135/Source.cpp) +65. [Bai137](../Bai137/Source.cpp) +66. [Bai139](../Bai139/Source.cpp) +67. [Bai140](../Bai140/Source.cpp) +68. [Bai142](../Bai142/Source.cpp) +69. [Bai144](../Bai144/Source.cpp) +70. [Bai145](../Bai145/Source.cpp) +71. [Bai147](../Bai147/Source.cpp) +72. [Bai149](../Bai149/Source.cpp) +73. [Bai150](../Bai150/Source.cpp) +74. [Bai152](../Bai152/Source.cpp) +75. [Bai154](../Bai154/Source.cpp) +76. [Bai155](../Bai155/Source.cpp) +77. [Bai157](../Bai157/Source.cpp) +78. [Bai159](../Bai159/Source.cpp) +79. [Bai160](../Bai160/Source.cpp) +80. [Bai162](../Bai162/Source.cpp) +81. [Bai164](../Bai164/Source.cpp) +82. [Bai165](../Bai165/Source.cpp) +83. [Bai167](../Bai167/Source.cpp) +84. [Bai169](../Bai169/Source.cpp) +85. [Bai170](../Bai170/Source.cpp) +86. [Bai172](../Bai172/Source.cpp) +87. [Bai174](../Bai174/Source.cpp) +88. [Bai175](../Bai175/Source.cpp) +89. [Bai177](../Bai177/Source.cpp) +90. [Bai179](../Bai179/Source.cpp) +91. [Bai180](../Bai180/Source.cpp) +92. [Bai182](../Bai182/Source.cpp) +93. [Bai184](../Bai184/Source.cpp) +94. [Bai185](../Bai185/Source.cpp) +95. [Bai187](../Bai187/Source.cpp) +96. [Bai189](../Bai189/Source.cpp) +97. [Bai190](../Bai190/Source.cpp) +98. [Bai192](../Bai192/Source.cpp) +99. [Bai194](../Bai194/Source.cpp) +100. [Bai195](../Bai195/Source.cpp) +101. [Bai197](../Bai197/Source.cpp) +102. [Bai199](../Bai199/Source.cpp) +103. [Bai200](../Bai200/Source.cpp) +104. [Bai202](../Bai202/Source.cpp) +105. [Bai204](../Bai204/Source.cpp) +106. [Bai205](../Bai205/Source.cpp) +107. [Bai207](../Bai207/Source.cpp) +108. [Bai209](../Bai209/Source.cpp) +109. [Bai210](../Bai210/Source.cpp) +110. [Bai212](../Bai212/Source.cpp) +111. [Bai214](../Bai214/Source.cpp) +112. [Bai215](../Bai215/Source.cpp) +113. [Bai217](../Bai217/Source.cpp) +114. [Bai219](../Bai219/Source.cpp) +115. [Bai220](../Bai220/Source.cpp) +116. [Bai222](../Bai222/Source.cpp) +117. [Bai224](../Bai224/Source.cpp) +118. [Bai225](../Bai225/Source.cpp) +119. [Bai227](../Bai227/Source.cpp) +120. [Bai229](../Bai229/Source.cpp) +121. [Bai230](../Bai230/Source.cpp) +122. [Bai232](../Bai232/Source.cpp) +123. [Bai234](../Bai234/Source.cpp) +124. [Bai235](../Bai235/Source.cpp) +125. [Bai237](../Bai237/Source.cpp) +126. [Bai239](../Bai239/Source.cpp) +127. [Bai240](../Bai240/Source.cpp) +128. [Bai242](../Bai242/Source.cpp) +129. [Bai244](../Bai244/Source.cpp) +130. [Bai245](../Bai245/Source.cpp) +131. [Bai247](../Bai247/Source.cpp) +132. [Bai249](../Bai249/Source.cpp) +133. [Bai250](../Bai250/Source.cpp) +134. [Bai252](../Bai252/Source.cpp) +135. [Bai254](../Bai254/Source.cpp) +136. [Bai255](../Bai255/Source.cpp) +137. [Bai257](../Bai257/Source.cpp) +138. [Bai259](../Bai259/Source.cpp) +139. [Bai260](../Bai260/Source.cpp) +140. [Bai262](../Bai262/Source.cpp) +141. [Bai264](../Bai264/Source.cpp) +142. [Bai265](../Bai265/Source.cpp) +143. [Bai267](../Bai267/Source.cpp) +144. [Bai269](../Bai269/Source.cpp) +145. [Bai270](../Bai270/Source.cpp) +146. [Bai272](../Bai272/Source.cpp) +147. [Bai274](../Bai274/Source.cpp) +148. [Bai275](../Bai275/Source.cpp) +149. [Bai277](../Bai277/Source.cpp) +150. [Bai279](../Bai279/Source.cpp) +151. [Bai280](../Bai280/Source.cpp) +152. [Bai282](../Bai282/Source.cpp) +153. [Bai284](../Bai284/Source.cpp) +154. [Bai285](../Bai285/Source.cpp) +155. [Bai287](../Bai287/Source.cpp) +156. [Bai289](../Bai289/Source.cpp) +157. [Bai290](../Bai290/Source.cpp)