Skip to content

Commit

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

using namespace std;

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

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

using namespace std;

float f(float x, int n){
return 2*x*x+n*x+n;
}

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

using namespace std;

void nhap(char c,float &n){
cout << "Nhap so thuc " << c << ": ";
cin >> n;
}

float max(float a, float b, float c){
if (a>=b&&a>=c) return a;
if (b>=a&&b>=c) return b;
if (c>=a&&c>=b) return c;
}

float min(float a, float b, float c){
if (a<=b&&a<=c) return a;
if (b<=a&&b<=c) return b;
if (c<=a&&c<=b) return c;
}

int main(){
float a,b,c;
nhap('a',a);
nhap('b',b);
nhap('c',c);
float d,e;
nhap('d',d);
nhap('e',e);
cout << "So nho nhat trong 5 so la " << min(min(a,b,c),d,e) << "\n";
cout << "So lon nhat trong 5 so la " << max(max(a,b,c),d,e) << "\n";
return 0;
}
45 changes: 45 additions & 0 deletions Bai thuc hanh so 3/bai4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <iostream>
#include <math.h>

using namespace std;

void nhap(char c,float &n){
cout << "Nhap so thuc " << c << ": ";
cin >> n;
}

int ptbh(float a, float b, float c, float &x1, float &x2){
float delta=b*b-4*a*c;
if (delta<0){
return 0;
}
else if (delta==0){
x1=-b/2*a;
x2=x1;
return 1;
}
else{
x1=(-b+sqrt(delta))/2*a;
x2=(-b-sqrt(delta))/2*a;
return 2;
}
}

int main(){
float a,b,c;
nhap('a',a);
nhap('b',b);
nhap('c',c);
float x1,x2;
int status = ptbh(a,b,c,x1,x2);
if (status==0){
cout << "Phuong trinh tren vo nghiem.\n";
}
else if (status==1){
cout << "Phuong trinh tren co nghiem kep x = " << x1 << ".\n";
}
else{
cout << "Phuong trinh tren co 2 nghiem phan biet x1 = " << x1 << " va x2 = " << x2 << ".\n";
}
return 0;
}
45 changes: 45 additions & 0 deletions Bai thuc hanh so 3/bai5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <iostream>

using namespace std;

void nhap(char c,float &n){
cout << "Nhap so thuc " << c << ": ";
cin >> n;
}

int hept(float a, float b, float c, float d, float e, float f, float &x, float &y){
float D=a*e-b*d;
float Dx=c*e-b*f;
float Dy=a*f-c*d;
if (D==0 && Dx==0)
return 1;
if (D==0 && Dx!=0)
return 0;
if (D!=0){
x=Dx/D;
y=Dy/D;
return 2;
}
}

int main(){
float a,b,c,d,e,f;
nhap('a',a);
nhap('b',b);
nhap('c',c);
nhap('d',d);
nhap('e',e);
nhap('f',f);
float x,y;
int status = hept(a,b,c,d,e,f,x,y);
if (status==0){
cout << "He phuong trinh tren vo nghiem.\n";
}
else if (status==1){
cout << "He phuong trinh tren co vo so nghiem.\n";
}
else{
cout << "He phuong trinh tren co mot nghiem x = " << x << " va y = " << y << ".\n";
}
return 0;
}

0 comments on commit d1a5679

Please sign in to comment.