Skip to content

Commit

Permalink
Add source code of Lesson 3B
Browse files Browse the repository at this point in the history
  • Loading branch information
lamhoangtung committed Jul 15, 2018
1 parent 37b1e1c commit b684209
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Bai thuc hanh so 3B/bai1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>

using namespace std;

long giaithua(int n){
if (n==1){
return 1;
}
else{
return (n*giaithua(n-1));
}
}

int main(){
int a,b;
cout << "Nhap so nguyen a: ";
cin >> a;
cout << "Nhap so nguyen b: ";
cin >> b;
float ans=(float)(giaithua(a)+giaithua(b))/giaithua(a+b);
cout << "(a!+b!)/(a+b)! = " << ans << "\n";
return 0;
}
20 changes: 20 additions & 0 deletions Bai thuc hanh so 3B/bai2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>

using namespace std;

float f(float x, int n){
if (n==1) return x;
else return (x/n*f(x,n-1));
}

int main(){
float x;
cout << "Nhap so thuc x: ";
cin >> x;
int n;
cout << "Nhap so nguyen n: ";
cin >> n;
float ans=f(x,n);
cout << "f(x,n) = " << ans << "\n";
return 0;
}
21 changes: 21 additions & 0 deletions Bai thuc hanh so 3B/bai3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
#include <math.h>

using namespace std;

float f(float x, int n){
if (n==0) return 2017;
else return (pow(x,n)+f(x,n-1));
}

int main(){
float x;
cout << "Nhap so thuc x: ";
cin >> x;
int n;
cout << "Nhap so nguyen n: ";
cin >> n;
float ans=f(x,n);
cout << "f(x,n) = " << ans << "\n";
return 0;
}
16 changes: 16 additions & 0 deletions Bai thuc hanh so 3B/bai4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <iostream>

using namespace std;

int dem(int n){
if (n>=0 && n<=9) return 1;
else return (dem(n/10)+1);
}

int main(){
int n;
cout << "Nhap so nguyen n: ";
cin >> n;
cout << "So nguyen " << n << " co " << dem(n) << " chu so.\n";
return 0;
}
22 changes: 22 additions & 0 deletions Bai thuc hanh so 3B/bai5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>

using namespace std;

int catalan(int n){
if (n==1 || n==2) return 1;
else{
int t=0;
for (int i=0;i<n;i++){
t+=catalan(i)*catalan(n-i);
}
return t;
}
}

int main(){
int n;
cout << "Nhap so nguyen duong n: ";
cin >> n;
cout << "Chu so CataLan thu " << n << " la " << catalan(n) << "\n";
return 0;
}

0 comments on commit b684209

Please sign in to comment.