Phần 1
Phần 1
Bài 1:
#include <iostream>
int main(){
int a;
cin >> a;
if (a%2==0)
else
return 0;
Bài 2:
#include <iostream>
int main(){
if (so1>so2)
else
return 0;
}
Bài 3:
#include <iostream>
int main(){
if (ng1 == ng2){
else if ((ng1 == 'B' && ng2 == 'K')||(ng1 == 'K' && ng2 == 'O')||(ng1 == 'O' && ng2
== 'B')){
else if ((ng1 == 'B' && ng2 == 'O')||(ng1 == 'K' && ng2 == 'B')||(ng1 == 'O' && ng2
== 'K')){
return 0;
Bài 4:
#include <iostream>
int main(){
float TNCT;
int heso3 = 3;
int heso4 = 4.5;
cout << "tham nien cong tac cua nhan vien la: ";
if (TNCT<12){
else if (TNCT>=60){
return 0;
Bài 5:
#include <iostream>
int main(){
if ((giobatdau<8) || (giobatdau>24))
return 0;
}
cout << "gio ket thuc la: ";
if ((gioketthuc>24) || (gioketthuc<8))
return 0;
cout << "so tien phai tra la: " << ((gioketthuc- giobatdau)*gia)-giamgia10;
cout << "so tien phai tra la: " << (((gioketthuc-
giobatdau)*giohatsau4tieng+27000)-giamgia);
cout << "so tien phai tra la: " << ((gioketthuc-giobatdau)*gia);
cout << "so tien phai tra la: " << (((gioketthuc-giobatdau)*21000)+27000);
return 0;
Bài 6:
Bài 7:
#include <iostream>
int main(){
){
cout << "so thu 1 la so lon nhat"<<endl << "so thu 3 la so nho nhat";
){
cout << "so thu 1 la so lon nhat"<<endl << "so thu 2 la so nho nhat";
cout << "so thu 2 la so lon nhat" << endl << "so thu 3 la so nho nhat";
cout << "so thu 2 la so lon nhat" << endl << "so thu 1 la so nho nhat";
cout << "so thu 3 la so lon nhat" << endl << "so thu 2 la so nho nhat" ;
cout << "so thu 3 la so lon nhat" << endl << "so thu 1 la so nho nhat";
}
return 0;
Bài 8:
#include <iostream>
int main(){
cout << "so thu 1 la so lon nhat"<<endl << "so thu 3 la so nho nhat";
else if (so1>so2 && (so1>so3) && (so1>so4) && (so3>so2) && (so4>so2))
cout << "so thu 1 la so lon nhat"<<endl << "so thu 2 la so nho nhat";
else if (so1>so2 && (so1>so3) && (so1>so4) && (so3>so4) && (so2>so4))
cout << "so thu 1 la so lon nhat"<<endl << "so thu 4 la so nho nhat";
else if ((so2>so1) && (so2>so3) && (so2>so4) && (so1>so3) && (so4>so3))
cout << "so thu 2 la so lon nhat" << endl << "so thu 3 la so nho nhat";
}
else if ((so2>so1) && (so2>so3) && (so2>so4) && (so1>so4) && (so3>so4))
cout << "so thu 2 la so lon nhat" << endl << "so thu 4 la so nho nhat";
else if ((so2>so1) && (so2>so3) && (so2>so4) && (so3>so1) && (so4>so1))
cout << "so thu 2 la so lon nhat" << endl << "so thu 1 la so nho nhat";
else if ((so3>so1) && (so3>so2) && (so3>so4) && (so1>so2) && (so4>so2))
cout << "so thu 3 la so lon nhat" << endl << "so thu 2 la so nho nhat" ;
else if ((so3>so1) && (so3>so2) && (so3>so4) && (so2>so1) && (so4>so1))
cout << "so thu 3 la so lon nhat" << endl << "so thu 1 la so nho nhat" ;
else if ((so3>so1) && (so3>so2) && (so3>so4) && (so1>so4) && (so2>so4))
cout << "so thu 3 la so lon nhat" << endl << "so thu 2 la so nho nhat" ;
else if ((so4>so1) && (so4>so2) && (so4>so3) && (so2>so1) && (so3>so1))
cout << "so thu 4 la so lon nhat" << endl << "so thu 1 la so nho nhat";
else if ((so4>so1) && (so4>so2) && (so4>so3) && (so1>so2) && (so3>so2))
cout << "so thu 4 la so lon nhat" << endl << "so thu 2 la so nho nhat";
else if ((so4>so1) && (so4>so2) && (so4>so3) && (so1>so3) && (so2>so3))
cout << "so thu 4 la so lon nhat" << endl << "so thu 3 la so nho nhat";
}
return 0;
Bài 9:
#include <iostream>
int main(){
int diemtrungbinh;
cout << "diem trung binh cua hoc sinh la: ";
if (diemtrungbinh<0 || diemtrungbinh>10)
return 0;
else if (diemtrungbinh>=9)
}
else if (diemtrungbinh>=3.5 && diemtrungbinh<5)
else
return 0;
Bài 10:
#include <iostream>
int main(){
float a, b;
cin >> a;
cin >> b;
if (a == 0 && b==0)
else if (a>0)
cout << "nghiem x cua phuong trinh là: " << -b/a;
}
else if (a<0)
cout << "nghiem x cua phuong trinh là: " << -b/a;
return 0;
Bài 11:
#include <iostream>
struct phanso {
int tuso;
int mauso;
};
do {
if (x.mauso == 0)
void xuatraphanso(phanso x) {
int main() {
NhapPS(phanso1);
NhapPS(phanso2);
xuatraphanso(phanso1);
xuatraphanso(phanso2);
cout << "\n" << "\n" <<"Tong hai phan so la: " << tongphanso(phanso1, phanso2);
cout << "\n" << "Hieu hai phan so la: " << hieuphanso(phanso1, phanso2);
cout << "\n" << "Tich hai phan so la: " << tichphanso(phanso1, phanso2);
cout << "\n" <<"Thuong hai phan so la: " << thuongphanso(phanso1, phanso2);
cout << endl;
return 0;
Bài 12:
#include <iostream>
#include <cctype>
int main() {
char kitu;
if (isupper(kitu))
else if (islower(kitu))
else if (isdigit(kitu))
else
}
return 0;
Bài 13:
#include <iostream>
int main(){
int luongdientieuthu;
cout << "so dien da tieu thu thang nay la: ";
if (luongdientieuthu<=0)
return 0;
else if (luongdientieuthu<=100)
int thue1;
thue1 = ((luongdientieuthu*550)*0.1);
cout << "tien dien thang nay la: " << (luongdientieuthu*550)+thue1 << "
VND";
int thue2;
thue2 = (((luongdientieuthu*900)-35000)*0.1);
cout << "tien dien thang nay la: " << ((luongdientieuthu*900)-35000)+thue2
<< " VND";
int thue3;
thue3 = (((100*550+50*900)+(luongdientieuthu-150)*1250)*0.1);
cout << "tien dien thang nay la: " << ((100*550+50*900)+(luongdientieuthu-
150)*1250)+thue3 << " VND";
int thue4;
thue4 = (((100*550+50*900+50*1250)+(luongdientieuthu-200)*1450)*0.1);
cout << "tien dien thang nay la: " << (((100*550+50*900+50*1250)+
(luongdientieuthu-200)*1450)+thue4);
else if (luongdientieuthu>300)
int thue5;
thue5 = (((100*550+50*900+50*1250+100*1450)+(luongdientieuthu-
300)*1700)*0.1);
return 0;
Bài 14:
#include <iostream>
int main(){
int maso;
if (maso == 1){
if (giolam<=40){
cout << "luong cua nhan vien tuan nay la: " << luongcoban*giolam
<< " VND";
else{
cout << "luong cua nhan vien tuan nay la: " <<
luongcoban*40+luongcoban*1.5*(giolam-40) << " VND";
else if (maso==3){
cout << "luong cua nhan vien tuan nay la: " << doanhso*0.07+500000 << " VND"
;
else if (maso==4){
cout << "luong cua nhan vien tuan nay la: " << sosanpham*sotiensanpham
<< " VND";
else{
return 0;
}
return 0;
Bài 15:
#include <iostream>
int main() {
int so;
return 1;
switch (hangchuc) {
switch (donvi) {
return 0;
Bài 16:
#include <iostream>
#include <cmath>
int main(){
cout << "giai phuon trinh bac 2 ax^2+bx+c=0 :" << endl;
int a, b, c, delta;
cin >> a;
cin >> b;
cin >> c;
if (delta>0){
x1=((-b+sqrt(delta))/2*a);
x2=((-b-sqrt(delta))/2*a);
cout << "phuong trinh co 2 nghiem: " << "\n" << "x1= " << x1 << "\n" <<
"x2= " << x2;
}
else if (delta=0){
cout << "phuong trinh co nghiem kep: " << "x= "<< -b/2*a;
else if (delta<0){
return 0;
Phần 2:
Bài 1:
#include <iostream>
int main() {
int n;
cin >> n;
if (n <= 0) {
ketqua *= i;
return 0;
Bài 2:
#include <iostream>
#include<string.h>
int main(){
int n;
cin >> n;
int s1 = 0;
s1 += i;
cout << "tong cac so nguyen S la: " << s1 << endl;
int s2 = 0;
s2 += i;
cout << "tong cac so nguyen cua S=2n+1 la: " << s2 << endl;
int s3 = 1;
s3 *=i;
}
cout << "giai thua cua n la: " << s3 << endl;
float s4 = 0;
s4 += i/(i(*i+1));
cout << "tong gia tri cua S la: " << s4;
return 0;
Bài 3:
#include <iostream>
int main(){
int n = 0;
cout << "cac so chia het cho 3 hoac 7 trong khoang tu 1 den 100 la: ";
if (i % 3 == 0 || i % 7 == 0){
n++;
cout << endl << "cac so chia het cho 3 va 7 trong khoang tu 1 den 100 la: " << n
<< endl;
return 0;
Bài 4:
#include <iostream>
bool isPrime(int n) {
return false;
return true;
int main() {
int n;
cin >> n;
if (isPrime(n)) {
} else {
cout << n << " khong phai la so nguyen to " << endl;
return 0;
Bài 5:
#include <iostream>
int main() {
int n;
cin >> n;
if (n <= 0) {
return 0;
int i = 2;
while (n > 1) {
if (n % i == 0) {
cout << i;
n /= i;
else {
i++;
return 0;
Bài 6:
#include <iostream>
int main() {
int soSinhVien;
if (soSinhVien <= 0) {
return 0;
float diemTrungBinh[soSinhVien];
float tongDiem = 0;
cout << "nhap diem trung binh cua sinh vien thu " << i + 1 << ": ";
tongDiem += diemTrungBinh[i];
cout << "\n diem trung binh cua cac sinh vien la :\n";
for (int i = 0; i < soSinhVien; i++) {
cout << "sinh vien thu " << i + 1 << ": " << diemTrungBinh[i] << endl;
cout << "\nDiem trung binh cua tat ca sinh vien la : " << diemTrungBinhTatCa << endl;
return 0;
Bài 7:
#include <iostream>
int main ()
float giaTriTrungBinh = 0;
float n;
do
cin >> n;
dem ++;
tong += n;
while(n!=9999);
giaTriTrungBinh =tong/dem;
cout << "Gia tri trung binh la:" << giaTriTrungBinh << endl;
return 0;
Bài 8:
#include<iostream>
using namespace std;
int main()
int n, m;
cout <<n << "*" << m << "=" << n*m <<'\t';
Bài 9:
#include <cmath>
#include <iostream>
int main(){
return 0;
Bài 10:
#include <iostream>
int M, N;
cin >> M;
cin >> N;
int a = M, b = N;
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
int ucln = a;
cout << "uoc chung lon nhat cua " << M << " va " << N << " la: " << ucln << endl;
cout << "boi chung nho nhat cua " << M << " va " << N << " la: " << bcnn << endl;
return 0;
Bài 11:
#include <iostream>
int main() {
cout << "Ma ASCII: " << ascii << " -> Ky tu: " << (char)ascii << " ";
if ((ascii - 33 + 1) % 7 == 0) {
ascii++;
}
return 0;
Bài 12:
#include <iostream>
int main() {
int n;
cin >> n;
cout << "so tien doi ra duoc la: " << endl;
if (count > 0) {
cout << "so to " << giatritien[i] << " nghin dong: " << count << endl;
n = n % giatritien[i];
return 0;
Bài 13 a:
#include <iostream>
#include <cstdlib>
#include <ctime>
int main()
int i;
int doan;
int soBiMat;
int soLanDoan;
return 0;
srand(time(0));
cout << "Lan doan thu " << i << ":" << doan << endl;
if (doan == soBiMat)
cout << "May doan dung, so bi mat la: " << soBiMat << endl;
return 0;
cout << "So bi mat lon hon " << doan << endl;
else
{
cout << "So bi mat nho hon " << doan << endl;
cout << "May khong doan duoc sau " << soLanDoan << " lan";
Bài 13 b:
#include <iostream>
#include <cstdlib>
#include <ctime>
int main()
int i;
int doan;
int soBiMat;
int soLanDoan;
srand(time(0));
cout << "Hay doan mot so trong khoang (1;100)" << endl;
if (doan == soBiMat)
{
cout << "Ban doan dung, so bi mat la: " << soBiMat << endl;
return 0;
cout << "So bi mat lon hon " << doan << endl;
else
cout << "So bi mat nho hon " << doan << endl;
cout << "Ban khong doan duoc sau " << soLanDoan << " lan";
Bài 14:
#include <iostream>
Using namespace std;
Int main (){
Int n, m;
Cout << “Nhap vao so nguyen n”;
Cin >> n;
for(int i = 0;i<=n;i++){
cout << ;
}
return 0;
}