This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/NMLT-NTTMK-K18/6-290-recursion
- Loading branch information
Showing
40 changed files
with
1,544 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,24 @@ | ||
#include <iostream> | ||
#include <iostream>; | ||
|
||
using namespace std; | ||
|
||
int Tong(int); | ||
|
||
int Tong(int n) | ||
{ | ||
if (n == 0) | ||
return 0; | ||
int s = Tong(n - 1); | ||
return (s + n * n); | ||
} | ||
|
||
int main() | ||
{ | ||
int k; | ||
cout << "Nhap n: "; | ||
cin >> k; | ||
|
||
return 0; | ||
int kq = Tong(k); | ||
cout << "S(" << k << ")= " << kq; | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
#include <iostream> | ||
#include <iomanip> | ||
using namespace std; | ||
|
||
float Tong(int); | ||
|
||
int main() | ||
{ | ||
|
||
int n; | ||
cout << "Nhap n: "; | ||
cin >> n; | ||
cout << "\nKet qua cua S(" << n << ") la: " << setw(5) << setprecision(5) << Tong(n) << endl; | ||
return 0; | ||
} | ||
|
||
float Tong(int n) { | ||
if (n == 0) { | ||
return 0; | ||
} | ||
return Tong(n - 1) + (float)n / (n + 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,29 @@ | ||
#include <iostream> | ||
#include <limits> | ||
#include <iomanip> | ||
#include <cmath> | ||
using namespace std; | ||
|
||
int sum(int); | ||
|
||
int main() | ||
{ | ||
int n; | ||
cout << "\nEnter the value of n: "; | ||
cin >> n; | ||
while (n > INT_MAX || n < 0) | ||
{ | ||
cout << "The inputted value of n is invalid. Please re-enter the value of n." << endl; | ||
cout << "\nEnter the value of n: "; | ||
cin >> n; | ||
} | ||
cout << "\nThe result of S(" << n << ") is: " << sum(n) << "." << endl; | ||
return 0; | ||
} | ||
|
||
return 0; | ||
int sum(int n) | ||
{ | ||
if (n == 0) | ||
return 0; | ||
return (sum(n - 1) + pow(n,4)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
float Tong(int); | ||
|
||
int main() | ||
{ | ||
int k; | ||
cout << "Nhap so nguyen: "; | ||
cin >> k; | ||
float kq = Tong(k); | ||
cout << "Tong la: " << kq; | ||
return 1; | ||
} | ||
|
||
return 0; | ||
float Tong(int n) | ||
{ | ||
if (n == 0) | ||
return 0; | ||
return (Tong(n - 1) + (float)1 / (n * (n + 1) * (n + 2))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,23 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
float Tong(float, int); | ||
|
||
int main() | ||
{ | ||
int k; | ||
float y; | ||
cout << "Nhap so nguyen: "; | ||
cin >> k; | ||
cin >> y; | ||
float kq = Tong(y, k); | ||
cout << "Ket qua la: " << kq; | ||
return 1; | ||
} | ||
|
||
return 0; | ||
float Tong(float x, int n) | ||
{ | ||
if (n == 0) | ||
return x; | ||
return (Tong(x, n - 1) * (x + n)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
#include <iostream> | ||
#include<iostream> | ||
#include<cmath> | ||
using namespace std; | ||
|
||
float sum(int); | ||
int main() | ||
{ | ||
|
||
return 0; | ||
int n; | ||
cin >> n; | ||
float kq = sum(n); | ||
cout << kq; | ||
return 0; | ||
|
||
} | ||
float sum(int n) | ||
{ | ||
if (n == 0) | ||
return 0; | ||
return sqrt(n + sum(n - 1)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,23 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int TinhAn(int); | ||
|
||
int TinhAn(int n) | ||
{ | ||
if (n == 1) | ||
return -2; | ||
return 5 * TinhAn(n - 1) + 12; | ||
} | ||
|
||
int main() | ||
{ | ||
int k; | ||
cout << "Nhap n: "; | ||
cin >> k; | ||
|
||
return 0; | ||
int kq = TinhAn(k); | ||
cout << "Ket qua la: " << kq; | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,30 @@ | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <cmath> | ||
using namespace std; | ||
|
||
float Dem_so_le(int); | ||
|
||
int main() | ||
{ | ||
|
||
int n; | ||
cout << "Nhap n: "; | ||
cin >> n; | ||
cout << "\nKet qua cua S(" << n << ") la: " << setw(5) << setprecision(5) << Dem_so_le(n) << endl; | ||
return 0; | ||
} | ||
|
||
float Dem_so_le(int n) { | ||
n = abs(n); | ||
if (n <= 9) { | ||
if (n % 2 == 1) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
int dv = n % 10; | ||
if (dv % 2 == 1) { | ||
return Dem_so_le(n / 10) + 1; | ||
} | ||
return Dem_so_le(n / 10); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,39 @@ | ||
#include <iostream> | ||
#include <limits> | ||
#include <iomanip> | ||
using namespace std; | ||
|
||
bool EvenExisted(int); | ||
|
||
int main() | ||
{ | ||
int n; | ||
cout << "\nEnter the value of n: "; | ||
cin >> n; | ||
while (n > INT_MAX || n < 0) | ||
{ | ||
cout << "The inputted value of n is invalid. Please re-enter the value of n." << endl; | ||
cout << "\nEnter the value of n: "; | ||
cin >> n; | ||
} | ||
if (EvenExisted(n) == true) | ||
cout << "\nIn the number " << n << " exists even digits." << endl; | ||
else | ||
cout << "\n In the number " << n << " doesn't exists even digits." << endl; | ||
cout << endl; | ||
return 0; | ||
} | ||
|
||
return 0; | ||
bool EvenExisted(int n) | ||
{ | ||
n = abs(n); | ||
if (n <= 9) | ||
{ | ||
if (n % 2 == 0) | ||
return true; | ||
return false; | ||
} | ||
int unit = n % 10; | ||
if (unit % 2 == 0) | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
#include <iostream> | ||
#include<iostream> | ||
using namespace std; | ||
|
||
long long a(int); | ||
long long b(int); | ||
int main() | ||
{ | ||
|
||
int n; | ||
cin >> n; | ||
long long kq = a(n); | ||
long long kq2 = b(n); | ||
cout << kq << " " << kq2; | ||
return 0; | ||
} | ||
long long a(int n) | ||
{ | ||
if (n == 1) | ||
return 2; | ||
return 3 * b(n - 1) + 2 * a(n - 1); | ||
|
||
} | ||
long long b(int n) | ||
{ | ||
if (n == 1) | ||
return 1; | ||
return a(n - 1) + 3 * b(n - 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <cmath> | ||
using namespace std; | ||
|
||
int S(int); | ||
|
||
int main() | ||
{ | ||
|
||
int n; | ||
cout << "Nhap n: "; | ||
cin >> n; | ||
cout << "\nKet qua cua S(" << n << ") la: " << setw(5) << S(n) << endl; | ||
return 0; | ||
} | ||
|
||
int S(int n) { | ||
if (n == 0) { | ||
return 0; | ||
} | ||
if (n == 1) { | ||
return 1; | ||
} | ||
return (1 + n) * S(n - 1) - n * S(n - 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,32 @@ | ||
#include <iostream> | ||
#include <limits> | ||
#include <iomanip> | ||
using namespace std; | ||
|
||
float sum(int); | ||
|
||
int main() | ||
{ | ||
int n; | ||
cout << "\nEnter the value of n: "; | ||
cin >> n; | ||
while (n > INT_MAX || n < 0) | ||
{ | ||
cout << "The inputted value of n is invalid. Please re-enter the value of n." << endl; | ||
cout << "\nEnter the value of n: "; | ||
cin >> n; | ||
} | ||
cout << "\nThe result of S(" << n << ") is: " << setw(5) << setprecision(5) << sum(n) << "." << endl; | ||
return 0; | ||
} | ||
|
||
return 0; | ||
float sum(int n) | ||
{ | ||
if (n == 0) | ||
return 0; | ||
if (n == 1) | ||
return 1; | ||
float a = sum(n - 1); | ||
float b = sum(n - 2); | ||
return (a + (float)1 /(n + 1 / (a - b))); | ||
} |
Oops, something went wrong.