Skip to content

Commit

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

using namespace std;

int main(){
int n;
cout << "Nhap so tien khach hang phai tra: ";
cin >> n;
float ans=n;
if (n>=200 && n<300){
ans-=n*0.2;
}
else if (n>=300){
ans-=n*0.3;
}
cout << "So tien khach hang phai tra la: " << ans << "\n";
return 0;
}
33 changes: 33 additions & 0 deletions Bai thuc hanh so 2/bai2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <math.h>

using namespace std;

int main(){
float a,b,c;
cout << "Nhap a: ";
cin >> a;
cout << "Nhap b: ";
cin >> b;
cout << "Nhao c: ";
cin >> c;
if (a==0){
cout << "Phuong trinh tren khong phai phuong trinh bac 2.\n";
}
else{
float delta = b*b-4*a*c;
if (delta<0){
cout << "Phuong trinh vo nghiem.\n";
}
else if (delta == 0){
float ans = -b/(2*a);
cout << "Phuong trinh tren co nghiem kep la " << ans << ".\n";
}
else{
float n1 = (-b+sqrt(delta))/(2*a);
float n2 = (-b-sqrt(delta))/(2*a);
cout << "Phuong trinh tren co 2 nghiem phan biet la " << n1 << " va " << n2 << ".\n";
}
}
return 0;
}
22 changes: 22 additions & 0 deletions Bai thuc hanh so 2/bai3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
#include <math.h>

using namespace std;

int main(){
float x;
int n;
cout << "Nhap vao mot so thuc x: ";
cin >> x;
cout << "Nhap vao mot so nguyen n: ";
cin >> n;
float s=0;
if (n%2==0){
s+=2016*x;
for (int i=2;i<=n;i++){
s+=(pow(x,i)/pow(3,i-1));
}
}
cout << "S = " << s << "\n";
return 0;
}
28 changes: 28 additions & 0 deletions Bai thuc hanh so 2/bai4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include <math.h>

using namespace std;

bool nguyento(int n){
if (n<2) return false;
for (int i=2;i<=sqrt(n);i++){
if (n%i==0) return false;
}
return true;
}

int main(){
int n;
cout << "Nhap n: ";
cin >> n;
int sum=0,count=0;
for (int i=1;i<=n;i++){
if (nguyento(i)==true){
sum+=i;
count++;
}
}
cout << "Co " << count << " so nguyen to trong doan tu 1 den " << n << ".\n";
cout << "Tong cua chung la " << sum << ".\n";
return 0;
}
24 changes: 24 additions & 0 deletions Bai thuc hanh so 2/bai5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>

using namespace std;

int main(){
int n;
cout << "Nhap so kWh dien tieu thu trong thang: ";
cin >> n;
long long ans;
if (n<=100){
ans=n*750;
}
else if (n>100 && n<=200){
ans=100*750+(n-100)*1250;
}
else if (n>200 && n<=300){
ans=100*750+100*1250+(n-200)*1750;
}
else{
ans=100*750+100*1250+100*1750+(n-300)*3000;
}
cout << "So tien dien ho tren phai tra la " << ans << " VND.\n";
return 0;
}

0 comments on commit 6412b44

Please sign in to comment.