Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Nov 14, 2023
2 parents c84ab15 + 442597d commit 4cc69f8
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 164 deletions.
26 changes: 26 additions & 0 deletions Bai057/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
#include <iostream>
#include <iomanip>
#include <cmath>
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);
}
84 changes: 81 additions & 3 deletions Bai062/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,86 @@
#include <iostream>
using namespace std;
#include<stdlib.h>
#include<stdio.h>

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;
}
42 changes: 38 additions & 4 deletions Bai067/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
#include <iostream>
#include <vector>

using namespace std;

int main()
{
void generate_permutations(vector<int>& seq, vector<int>& curr_perm, vector<bool>& 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<int> 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<int> curr_perm;
vector<bool> used(n, false);
generate_permutations(seq, curr_perm, used);

return 0;
}
return 0;
}
35 changes: 34 additions & 1 deletion Bai072/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
#include <iostream>
#include <cstdlib>
#include <iomanip>

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];
}
35 changes: 34 additions & 1 deletion Bai077/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
#include <iostream>
#include <cstdlib>
#include <iomanip>

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;
}
54 changes: 53 additions & 1 deletion Bai082/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,60 @@
#include <iostream>
#include <cstdlib>
#include <iomanip>

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;

}
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
Loading

0 comments on commit 4cc69f8

Please sign in to comment.