- Cho một số nguyên n. Hãy tính và in ra:
- Giá trị n²
Giá trị n⁵ - Input
Một số nguyên n (−1000 ≤ n ≤ 1000). - Output
Giá trị n² và n⁵, mỗi kết quả in trên một dòng.
Ví dụ
Ví dụ 1:
Input
2
Output
4
32
Ví dụ 2:
Input
-3
Output
9
-243Lập trình C++
DANH SÁCH TÓM TẮT:
Ngôn ngữ lập trình C++ từ lâu đã trở thành một công cụ quan trọng trong việc học tập và nghiên cứu Tin học. Không chỉ giúp rèn luyện tư duy logic, C++ còn là nền tảng vững chắc để học sinh, sinh viên tiếp cận các kiến thức chuyên sâu hơn về cấu trúc dữ liệu, giải thuật và lập trình thi đấu.
Tài liệu “100 bài tập C++ từ cơ bản đến nâng cao – Có lời giải (2025-2026)” được biên soạn nhằm hỗ trợ các em học sinh, sinh viên cũng như những người yêu thích lập trình có một bộ bài tập thực hành đa dạng, hệ thống và có lời giải chi tiết. Các bài tập được sắp xếp từ mức độ cơ bản (cấu trúc rẽ nhánh, vòng lặp, mảng, chuỗi) đến nâng cao (đệ quy, quy hoạch động, đồ thị, thuật toán tham lam, cấu trúc dữ liệu).
Mỗi bài toán không chỉ đưa ra đề bài rõ ràng mà còn có hướng dẫn và lời giải bằng C++, giúp người học dễ dàng đối chiếu, rút kinh nghiệm và mở rộng tư duy. Bộ tài liệu này đồng thời cũng là nguồn tham khảo hữu ích cho các bạn học sinh chuẩn bị cho các kỳ thi Tin học, từ thi học sinh giỏi đến các kỳ thi tuyển sinh chuyên Tin.
Hy vọng rằng với tài liệu này, người học sẽ:
Củng cố kiến thức lập trình C++.
Nâng cao khả năng phân tích và giải quyết vấn đề.
Tự tin hơn khi bước vào các kỳ thi lập trình và ứng dụng thực tế.
Ví dụ
Ví dụ 1:
Ví dụ 2:
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int res=n+2025;
cout<<res;
return 0;
} Ví dụ
Ví dụ 1:
Ví dụ 2:
#include <iostream>
using namespace std;
int main()
{
int a;
cin>>a;
int res=a-2;
cout<<res;
return 0;
}
Dòng 1: Chuỗi s (không quá 1000 ký tự).
Dòng 2: Một ký tự c.
Ví dụ
Ví dụ 1:
Ví dụ 2:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
char c;
getline(cin, s);
cin >> c;
string kq = "";
for (int i = 0; i < s.length(); i++)
{
if (s[i] != c) kq += s[i];
}
cout << kq;
return 0;
}
Ví dụ
Ví dụ 1:
Ví dụ 2:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin>>n;
double res=(double)n/4;
cout<<setprecision(2)<<fixed<<res;
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
cin>>n;
int res1=pow(n,2);
int res2=pow(n,5);
cout<<res1<<"\n";
cout<<res2;
return 0;
}
Ví dụ
Ví dụ 1:
Ví dụ 2:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int n;
cin>>n;
double res=sqrt(n);
cout<<setprecision(2)<<fixed<<res;
return 0;
}
Ví dụ
Ví dụ 1:
Ví dụ 2:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin>>n;
double res= 1/double(n);
cout<<setprecision(5)<<fixed<<res;
return 0;
}
Input
Hai số nguyên a và b (−1000 ≤ a, b ≤ 1000, b ≠ 0).
Output
Dòng 1: Giá trị P và Q (cách nhau một khoảng trắng).
Dòng 2: Giá trị R.
Ví dụ
Ví dụ 1:
Ví dụ 2:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int P=21*a+5*b-2009;
double Q=(21*(pow(a,2)-5*b))/(2009*(pow(b,2)));
double R=((21*a+(5*pow(b,2)))/(2009*b+15));
cout<<P<<" "<<Q<<"\n";
cout<<R;
return 0;
}
Ví dụ
Ví dụ 1:
Ví dụ 2:
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int q = a / b;
int r = a % b;
cout << q << " " << r;
return 0;
}
Ví dụ
Ví dụ 1:
Ví dụ 2:
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a / b << " " << a % b;
return 0;
} Ví dụ
Ví dụ 1:
Ví dụ 2:
#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
cout << m / n << " " << m % n;
return 0;
} #include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int donvi = n % 10;
int chuc = n / 10;
cout << donvi << " " << chuc;
return 0;
}
Ví dụ 1:
Ví dụ 2:
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int nghin = n / 1000;
int tram = (n / 100) % 10;
int chuc = (n / 10) % 10;
int donvi = n % 10;
cout << nghin + tram + chuc + donvi;
return 0;
}
Ví dụ
Ví dụ 1:
Ví dụ 2:
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << (a % 10) + (b % 10);
return 0;
}
a và b. Hãy tính tổng của chữ số hàng đơn vị của a và chữ số hàng chục của b.a và b (−10^9 ≤ a, b ≤ 10^9).Ví dụ 1:
Giải thích: chữ số hàng đơn vị của 27 là 7, chữ số hàng chục của 35 là 3. Tổng = 7 + 3 = 10.
Ví dụ 2:
Giải thích: chữ số hàng đơn vị của 123 là 3, chữ số hàng chục của 456 là 5. Tổng = 3 + 5 = 8.
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << (a % 10) + ((b / 10) % 10);
return 0;
}
Nhập vào một số nguyên n có 3 chữ số. Hãy in ra lần lượt:
Chữ số hàng trăm
Chữ số hàng chục
Chữ số hàng đơn vị
n (100 ≤ n ≤ 999).Ví dụ 1
Ví dụ 2
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
cout << n / 5000 << " " << n % 5000;
return 0;
}
n (số tiền, bội số của 1000). Hãy đổi số tiền đó thành các tờ 5000, 2000, 1000 sao cho số tờ tiền là ít nhất.Input
Output
Input
Output
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int to5000 = n / 5000;
n %= 5000;
int to2000 = n / 2000;
n %= 2000;
int to1000 = n / 1000;
cout << to5000 << " " << to2000 << " " << to1000;
return 0;
}
n (số giây). Hãy đổi n giây thành dạng giờ:phút:giây và in ra kết quả theo đúng định dạng.Input
Output
Input
Output
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int h = n / 3600;
n %= 3600;
int m = n / 60;
int s = n % 60;
cout << h << ":" << m << ":" << s;
return 0;
}
a, b, c học sinh.Input
Output
Input
Output
#include <iostream>
using namespace std;
int main() {
long long a, b, c;
cin >> a >> b >> c;
long long desks = (a + 1) / 2 + (b + 1) / 2 + (c + 1) / 2;
cout << desks;
return 0;
}
Đề bài
Cho một đoạn thẳng có độ dài L. Người ta muốn chia đoạn thẳng này thành các đoạn nhỏ có cùng độ dài d.
Hãy tính:
Số đoạn nhỏ chia được.
Độ dài đoạn thừa (nếu có).
Input
Output
Input
Output
#include <iostream>
using namespace std;
int main() {
int L, d;
cin >> L >> d;
int soDoan = L / d;
int du = L % d;
cout << soDoan << " " << du;
return 0;
}
Nhập vào độ dài cạnh của một hình vuông a.
Hãy tính:
Chu vi của hình vuông.
Diện tích của hình vuông.
Input
Output
Input
Output
#include <iostream>
using namespace std;
int main() {
int a;
cin >> a;
int chuVi = 4 * a;
int dienTich = a * a;
cout << chuVi << " " << dienTich;
return 0;
}
Nhập vào bán kính r của hình tròn.
Hãy tính:
Chu vi hình tròn.
Diện tích hình tròn.
Kết quả in ra với 2 chữ số thập phân.
Input
Output
Input
Output
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
int r;
cin >> r;
double chuVi = 2 * M_PI * r;
double dienTich = M_PI * r * r;
cout << fixed << setprecision(2) << chuVi << " " << dienTich;
return 0;
}
Nhập vào 2 số nguyên dương a, b là chiều dài và chiều rộng của hình chữ nhật.
Hãy tính:
Chu vi hình chữ nhật.
Diện tích hình chữ nhật.
Input
Output
Input
Output
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int cv = (a + b) * 2;
int dt = a * b;
cout << cv << " " << dt;
return 0;
}
Nhập vào độ dài cạnh đáy a và chiều cao h của một tam giác.
Tính diện tích của tam giác theo công thức:
Kết quả in ra với 1 chữ số thập phân.
Input
Output
Input
Output
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double a, h;
cin >> a >> h;
double S = (a * h) / 2;
cout << fixed << setprecision(1) << S;
return 0;
}
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
double a, b, c;
cin >> a >> b >> c;
double cv = a + b + c;
double p = cv / 2.0;
double s = sqrt(p * (p - a) * (p - b) * (p - c));
cout << fixed << setprecision(0) << cv << endl;
cout << fixed << setprecision(3) << s << endl;
return 0;
}
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
double a, b, c;
cin >> a >> b >> c;
double p = (a + b + c) / 2.0;
double S = sqrt(p * (p - a) * (p - b) * (p - c));
double R = (a * b * c) / (4.0 * S);
cout << fixed << setprecision(3) << R << endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
double tbc = (a + b + c) / 3.0;
cout << fixed << setprecision(1) << tbc;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double toan, van, anh;
cin >> toan >> van >> anh;
double tbc = (2*toan + 2*van + anh) / 5.0;
cout << fixed << setprecision(1) << tbc;
return 0;
}
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
double C;
cin >> C;
double S = (C * C) / (4 * M_PI);
cout << fixed << setprecision(2) << S << endl;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int C;
cin >> C;
int a = C / 4;
int S = a * a;
cout << S << endl;
return 0;
}
#include <iostream>
using namespace std;
int main() {
float an, binh;
cin >> an >> binh;
if (an > binh)
cout << "An gioi hon" << endl;
if (binh > an)
cout << "Binh gioi hon" << endl;
if (an == binh)
cout << "Bang nhau" << endl;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int an, binh;
cin >> an >> binh;
if (an < binh)
cout << "An nhanh hon" << endl;
if (binh < an)
cout << "Binh nhanh hon" << endl;
if (an == binh)
cout << "Bang nhau" << endl;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1) cout << "One";
if (n == 2) cout << "Two";
if (n == 3) cout << "Three";
if (n == 4) cout << "Four";
if (n == 5) cout << "Five";
if (n == 6) cout << "Six";
if (n == 7) cout << "Seven";
if (n == 8) cout << "Eight";
if (n == 9) cout << "Nine";
if (n == 10) cout << "Ten";
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a > b && a > c) cout << a;
if (b > a && b > c) cout << b;
if (c > a && c > b) cout << c;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int t;
cin >> t;
if (t > 0 && t <= 11) cout << "Thieu nhi";
if (t > 11 && t <= 25) cout << "Thieu nien";
if (t > 25 && t <= 50) cout << "Trung nien";
if (t > 50) cout << "Lao nien";
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double HKI, HKII;
cin >> HKI >> HKII;
double TBCN = (HKI + HKII * 2) / 3.0;
cout << fixed << setprecision(1) << TBCN << endl;
if (TBCN >= 8.0) cout << "Gioi";
if (TBCN >= 6.5 && TBCN < 8.0) cout << "Kha";
if (TBCN >= 5.0 && TBCN < 6.5) cout << "Trung binh";
if (TBCN >= 3.5 && TBCN < 5.0) cout << "Yeu";
if (TBCN < 3.5) cout << "Kem";
return 0;
}
#include <iostream>
using namespace std;
int main() {
int thang;
cin >> thang;
if (thang == 2 || thang == 3 || thang == 4) cout << "Mua Xuan";
if (thang == 5 || thang == 6 || thang == 7) cout << "Mua Ha";
if (thang == 8 || thang == 9 || thang == 10) cout << "Mua Thu";
if (thang == 11 || thang == 12 || thang == 1) cout << "Mua Dong";
return 0;
}
#include <iostream>
using namespace std;
int main() {
int t;
cin >> t;
if (t >= 0 && t <= 20) cout << "Mua Dong";
if (t >= 21 && t <= 25) cout << "Mua Xuan";
if (t >= 26 && t <= 30) cout << "Mua Thu";
if (t > 30) cout << "Mua Ha";
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if (n > 0) cout << "So duong";
if (n < 0) cout << "So am";
if (n == 0) cout << "So khong";
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (a == 0 || b == 0) cout << 0;
if ((a > 0 && b > 0) || (a < 0 && b < 0)) cout << 1;
if ((a > 0 && b < 0) || (a < 0 && b > 0)) cout << -1;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 6 == 0)
cout << "Yes";
else
cout << "No";
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if (n > 100)
cout << "Yes";
else
cout << "No";
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if (n > 80) {
cout << "Beo phi";
} else if (n < 45) {
cout << "Suy dinh duong";
} else {
cout << "Binh thuong";
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if (n > 180) {
cout << "Huu cao co";
} else if (n < 100) {
cout << "Nam lun cute";
} else {
cout << "Binh thuong";
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int t, n;
cin >> t >> n;
int ngay;
// Kiểm tra năm nhuận
bool namNhuan = (n % 400 == 0) || (n % 4 == 0 && n % 100 != 0);
if (t == 2) {
if (namNhuan) {
ngay = 29;
} else {
ngay = 28;
}
} else if (t == 4 || t == 6 || t == 9 || t == 11) {
ngay = 30;
} else {
ngay = 31;
}
cout << ngay;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int soXe;
cin >> soXe;
int tong = 0, tmp = soXe;
while (tmp > 0) {
tong += tmp % 10;
tmp /= 10;
}
int nut = tong % 10;
cout << nut << endl;
if (nut == 9) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
cin >> n;
if (n < 0) {
cout << "No";
} else {
int sq = sqrt(n);
if (sq * sq == n) {
cout << "Yes";
} else {
cout << "No";
}
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a + b > c && a + c > b && b + c > a) {
cout << "Yes" << endl;
// Kiểm tra tam giác đều
if (a == b && b == c) {
cout << "Deu";
}
else if (a*a + b*b == c*c || a*a + c*c == b*b || b*b + c*c == a*a) {
cout << "Vuong";
}
else if (a == b || b == c || a == c) {
cout << "Can";
}
else {
cout << "Thuong";
}
} else {
cout << "No";
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int km;
cin >> km;
int tien = 0;
if (km <= 0) {
tien = 0;
} else if (km == 1) {
tien = 12000;
} else if (km <= 30) {
tien = 12000 + (km - 1) * 10000;
} else {
tien = 12000 + 29 * 10000 + (km - 30) * 9000;
}
cout << tien;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int kWh;
cin >> kWh;
int tien = 0;
if (kWh <= 50) {
tien = kWh * 600;
} else if (kWh <= 100) {
tien = 50 * 600 + (kWh - 50) * 800;
} else if (kWh <= 200) {
tien = 50 * 600 + 50 * 800 + (kWh - 100) * 1100;
} else {
tien = 50 * 600 + 50 * 800 + 100 * 1100 + (kWh - 200) * 1500;
}
cout << tien;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 == 0) {
cout << "Chan" << endl;
if (n > 0) {
cout << "Duong";
} else if (n < 0) {
cout << "Am";
} else {
cout << "Khong";
}
} else {
cout << "Le" << endl;
if (n > 0) {
cout << "Duong";
} else {
cout << "Am";
}
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int diem;
cin >> diem;
if (diem >= 85) {
cout << "Loai A" << endl;
} else if (diem >= 60) {
cout << "Loai B" << endl;
} else {
cout << "Loai C" << endl;
}
if (diem >= 90) {
cout << "Xuat sac";
} else if (diem >= 80) {
cout << "Gioi";
} else if (diem >= 70) {
cout << "Kha";
} else if (diem >= 60) {
cout << "Trung binh";
} else if (diem >= 50) {
cout << "Yeu";
} else {
cout << "Kem";
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int age;
cin >> age;
if (age <= 15) {
cout << "Tre em" << endl;
} else if (age <= 60) {
cout << "Nguoi truong thanh" << endl;
} else {
cout << "Nguoi cao tuoi" << endl;
}
if (age <= 5) {
cout << "Tre mam non";
} else if (age <= 10) {
cout << "Tre tieu hoc";
} else if (age <= 15) {
cout << "Tre trung hoc";
} else if (age <= 22) {
cout << "Sinh vien";
} else if (age <= 60) {
cout << "Nguoi di lam";
} else if (age <= 65) {
cout << "Sap nghi huu";
} else {
cout << "Da nghi huu";
}
return 0;
}
#include <iostream>
using namespace std>
#include <iomanip>
int main() {
int n;
cin >> n;
int firstTwo = n / 10;
int lastTwo = n % 100;
cout << firstTwo << " " << setw(2) << setfill('0') << lastTwo;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a == b && b == c && c == d) {
cout << "=";
} else {
int maxVal = a;
if (b > maxVal) maxVal = b;
if (c > maxVal) maxVal = c;
if (d > maxVal) maxVal = d;
cout << maxVal;
}
return 0;
}
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
double a, b, c;
cin >> a >> b >> c;
if (a + b > c && a + c > b && b + c > a) {
cout << "Day la 3 canh cua mot tam giac" << endl;
double chuVi = a + b + c;
double p = chuVi / 2; // nửa chu vi
double dienTich = sqrt(p * (p - a) * (p - b) * (p - c));
cout << fixed << setprecision(2) << chuVi << " "
<< fixed << setprecision(1) << dienTich;
} else {
cout << "Day khong phai la 3 canh cua mot tam giac";
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (a > 0 && b > 0) {
cout << "Day la 2 kich thuoc cua mot hinh chu nhat" << endl;
int chuVi = 2 * (a + b);
int dienTich = a * b;
cout << chuVi << " " << dienTich;
} else {
cout << "Day khong phai la 2 kich thuoc cua mot hinh chu nhat" << endl;
if (a <= 0 && b <= 0) {
cout << "a va b la so am";
} else if (a <= 0) {
cout << "a la so am";
} else {
cout << "b la so am";
}
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
long long n;
cin >> n;
string s = to_string(n);
bool hasLe = false;
for (char c : s) {
int digit = c - '0';
if (digit % 2 != 0) {
if (hasLe) cout << " ";
cout << digit;
hasLe = true;
}
}
if (!hasLe) {
cout << "-";
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
long long n;
cin >> n;
string s = to_string(n);
int tong = 0;
for (char c : s) {
int digit = c - '0';
if (digit % 2 == 0) {
tong += digit;
}
}
if (tong == 0) {
cout << "-";
} else {
cout << tong;
}
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main() {
long long a;
cin >> a;
string s = to_string(a);
int maxDigit = s[0] - '0';
int minDigit = s[0] - '0';
for (char c : s) {
int digit = c - '0';
if (digit > maxDigit) maxDigit = digit;
if (digit < minDigit) minDigit = digit;
}
cout << maxDigit << " " << minDigit;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
if (i > 1) cout << " ";
cout << i;
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int tong = 0;
for (int i = 1; i <= n; i++) {
tong += i;
}
cout << tong;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 3; i <= n; i += 3) {
if (i > 3) cout << " ";
cout << i;
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int count = n / 3;
cout << count;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int tong = 0;
for (int i = 2; i <= n; i += 2) {
tong += i;
}
cout << tong;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int tong = 0;
for (int i = 15; i <= n; i += 15) {
tong += i;
}
cout << tong;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int tong = 0;
for (int i = 1; i <= n; i++) {
if (i % 3 == 0 || i % 5 == 0) {
tong += i;
}
}
cout << tong;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int tong = 0;
for (int i = 1; i <= n; i++) {
if (i % 3 == 0 || i % 5 == 0) {
tong += i;
}
}
cout << tong;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int n;
cin >> n;
int tong = 0, dem = 0;
for (int i = 1; i <= n; i++) {
if (i % 5 == 0) {
tong += i;
dem++;
}
}
if (dem == 0) {
cout << "-";
} else {
double trungBinh = (double)tong / dem;
cout << fixed << setprecision(1) << trungBinh;
}
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int n;
cin >> n;
int tong = 0, dem = 0;
for (int i = 15; i <= n; i += 15) {
tong += i;
dem++;
}
if (dem == 0) {
cout << "-";
} else {
double trungBinh = (double)tong / dem;
cout << fixed << setprecision(1) << trungBinh;
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
for (int i = a; i <= b; i++) {
if (i > a) cout << " ";
cout << i;
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int tong = 0;
for (int i = a; i <= b; i++) {
tong += i;
}
cout << tong;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int count = 0;
for (int i = a; i <= b; i++) {
if (i % 3 == 0) {
count++;
}
}
cout << count;
return 0;
} #include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
bool hasEven = false;
for (int i = a; i <= b; i++) {
if (i % 2 == 0) {
if (hasEven) cout << " ";
cout << i;
hasEven = true;
}
}
if (!hasEven) cout << "-";
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int dem = 0;
for (int i = a; i <= b; i++) {
if (i % 2 == 0) {
dem++;
}
}
cout << dem;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int count = 0;
for (int i = a; i <= b; i++) {
if (i % 2 == 0) {
count++;
}
}
cout << count;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int tong = 0, dem = 0;
for (int i = a; i <= b; i++) {
if (i % 2 == 0) {
tong += i;
dem++;
}
}
if (dem == 0) {
cout << "-";
} else {
cout << tong / dem;
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int tong5 = 0;
int tong2_3 = 0, dem2_3 = 0;
for (int i = a; i <= b; i++) {
if (i % 5 == 0) {
tong5 += i;
}
if (i % 2 == 0 && i % 3 == 0) {
tong2_3 += i;
dem2_3++;
}
}
int trungBinh2_3 = (dem2_3 == 0) ? 0 : tong2_3 / dem2_3;
cout << tong5 << " " << trungBinh2_3;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int dem7 = 0;
int tong2_3 = 0, dem2_3 = 0;
for (int i = a; i <= b; i++) {
if (i % 7 == 0) {
dem7++;
}
if (i % 2 == 0 || i % 3 == 0) {
tong2_3 += i;
dem2_3++;
}
}
double trungBinh2_3 = (dem2_3 == 0) ? 0.0 : (double)tong2_3 / dem2_3;
cout << dem7 << " " << fixed << setprecision(1) << trungBinh2_3;
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
vector<int> chia5;
for (int i = a; i <= b; i++) {
if (i % 5 == 0) {
chia5.push_back(i);
}
}
cout << chia5.size() << " -";
for (int num : chia5) {
cout << " " << num;
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
a = abs(a);
b = abs(b);
while (b != 0) {
int r = a % b;
a = b;
b = r;
}
cout << a;
return 0;
}
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
string s;
getline(cin,s);
stringstream ss(s);
string w;
vector<string>ws;
while (ss>>w)
{
ws.push_back(w);
}
for (int i=0; i<ws.size()-1;i++)
{
cout<<ws[i]<<" ";
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
long long so;
cin >> so;
if (so == 0) {
cout << 1;
return 0;
}
if (so < 0) so = -so;
int dem = 0;
while (so > 0) {
so /= 10;
dem++;
}
cout << dem;
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long so;
cin >> so;
if (so < 0) so = -so;
vector<int> chu_so_vec;
if (so == 0) chu_so_vec.push_back(0);
while (so > 0) {
chu_so_vec.push_back(so % 10);
so /= 10;
}
for (int i = chu_so_vec.size() - 1; i >= 0; i--) {
cout << chu_so_vec[i];
if (i > 0) cout << " ";
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
long long so;
cin >> so;
if (so < 0) so = -so;
int tong = 0;
while (so > 0) {
tong += so % 10;
so /= 10;
}
cout << tong;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int a[20],k=0;
while (n>0)
{
int res=n%10;
if (res%2==0)
{
a[k++]=res;
}
n/=10;
}
for (int i=k-1; i>=0;i--)
{
cout<<a[i]<< " ";
}
return 0;
}
#include <iostream>
using namespace std;
string kt_so_chia_het_cho_5(int n)
{
if (n%5==0)
{
return "Yes";
}
return "No";
}
int main()
{
int n;
cin>>n;
string res=kt_so_chia_het_cho_5(n);
cout<<res<<"\n";
return 0;
}
#include <iostream>
using namespace std;
int ucln(int a,int b)
{
while (a!=b)
{
if (a>b)
{
a-=b;
}
else
{
b-=a;
}
}
return a;
}
int main()
{
int a,b;
cin>>a>>b;
int U=ucln(a,b);
int tu=a/U;
int mau=b/U;
cout<<tu<<"/"<<mau;
return 0;
}
#include <iostream>
using namespace std;
int main() {
long long so;
cin >> so;
if (so < 0) so = -so;
int dem_le = 0;
while (so > 0) {
int chu_so = so % 10;
if (chu_so % 2 != 0) {
dem_le++;
}
so /= 10;
}
cout << dem_le;
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int k, x;
cin >> k >> x;
int a, n;
int result = 0;
for (int i = 0; i < k; i++) {
cin >> a >> n;
result += a * pow(x, n);
}
cout << result << endl;
return 0;
}
#include <iostream>
using namespace std;
void in_dong(int d) {
for (int i = 0; i < d; i++) cout << '*';
cout << endl;
}
void in_dong_rong(int d) {
cout << '*';
for (int i = 0; i < d - 2; i++) cout << ' ';
if (d > 1) cout << '*';
cout << endl;
}
int main() {
int d, r;
cin >> d >> r;
if (r >= 1) in_dong(d);
for (int i = 0; i < r - 2; i++) in_dong_rong(d);
if (r > 1) in_dong(d);
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int cong(int a, int b) {
return a + b;
}
double chia(double a, double b) {
return a / b;
}
int main() {
int a, b, c;
cin >> a >> b >> c;
int tong = cong(a, cong(b, c));
double thu2 = (double)a/b+c;
double thu3 = chia(a, (b + c));
cout << tong << " ";
cout << fixed << setprecision(2) << thu2 << " ";
cout << fixed << setprecision(3) << thu3 << endl;
return 0;
}
#include <iostream>
using namespace std;
int min2(int x, int y) {
return (x < y) ? x : y;
}
int main() {
int a, b, c;
cin >> a >> b >> c;
int res = min2(a, min2(b, c));
cout << res << endl;
return 0;
}
#include <iostream>
using namespace std;
int main() {
long long so;
cin >> so;
if (so < 0) so = -so;
int chan_nho_nhat = 10;
while (so > 0) {
int chu_so = so % 10;
if (chu_so % 2 == 0 && chu_so < chan_nho_nhat) {
chan_nho_nhat = chu_so;
}
so /= 10;
}
if (chan_nho_nhat == 10) cout << "-";
else cout << chan_nho_nhat;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
int t=0,d=n;
for (int i=0;i<n;i++)
{
cin>>a[i];
t+=a[i];
}
double tbc=(double)t/d;
cout<<setprecision(1)<<fixed<<tbc;
return 0;
}
#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n],t=0,d=0;
for (int i=0; i<n; i++)
{
cin>>a[i];
if (a[i]%2==0)
{
d++;
t+=a[i];
}
}
if (d==0) cout<<"-";
else
{
double tbc=(double)t/d;
cout<<setprecision(2)<<fixed<<tbc;
}
return 0;
}
#include <iostream>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
bool ktnt(int n)
{
if (n<2) return 0;
for (int i=2; i*i<=n; i++)
{
if (n%i==0) return 0;
}
return 1;
}
int main()
{
string line;
getline(cin,line);
stringstream ss(line);
int x,d=0;
while (ss>>x)
{
if (ktnt(x)) d++;
}
if (d==0) cout<<"-";
else
{
cout<<d;
}
return 0;
}
#include <iostream>
using namespace std;
int ktnt(int n)
{
if (n<2) return 0;
for (int i=2; i*i<=n;i++)
{
if (n%i==0) return 0;
}
return 1;
}
int main()
{
int n;
cin>>n;
int i=0,d=0,t=0;
while (d<n)
{
if (ktnt(i) && ktnt(i+2))
{
d++;
t+=i;
}
i++;
}
cout<<t;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin>>n;
int d=0,t=0,i=0;
while (d<n)
{
if (i%3!=0)
{
d++;
t+=i;
}
i++;
}
double tbc=t*1.0/d;
cout<<setprecision(1)<<fixed<<tbc;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int d=0,t=a,k=a*0.02;
while (t<=b)
{
t=t+k;
k=t*0.02;
d++;
}
cout<<d;
return 0;
}
Bộ tài liệu 100 bài tập C++ từ cơ bản đến nâng cao ra đời nhằm cung cấp cho các bạn học sinh, sinh viên và những người yêu thích lập trình một hành trang vững chắc để rèn luyện kỹ năng lập trình C++ một cách toàn diện. Qua 100 bài tập, từ những bài cơ bản về biến, kiểu dữ liệu, cấu trúc điều kiện, vòng lặp, mảng, chuỗi, đến những bài nâng cao về hàm, con trỏ, cấu trúc dữ liệu, thuật toán, lập trình hướng đối tượng và các bài toán thực tiễn, người học sẽ từng bước củng cố lý thuyết, nâng cao tư duy giải quyết vấn đề và phát triển khả năng tự học.
Điểm đặc biệt của tài liệu là mọi bài tập đều kèm lời giải chi tiết, hướng dẫn từng bước thực hiện và giải thích thuật toán. Điều này không chỉ giúp người học hiểu rõ cách giải mà còn rèn luyện kỹ năng đọc hiểu code, tối ưu thuật toán và phát hiện lỗi. Thêm vào đó, các bài tập được sắp xếp theo mức độ khó tăng dần, từ dễ đến khó, giúp người học dễ dàng theo dõi, luyện tập theo năng lực, đồng thời tạo nền tảng để tiếp cận các bài toán phức tạp trong các kỳ thi tin học, lập trình, hoặc ứng dụng trong thực tế.
Trong quá trình học, người học được khuyến khích thử sức với các biến thể của bài tập, tự viết code và kiểm tra kết quả. Sự kết hợp giữa lý thuyết, thực hành và tự đánh giá sẽ giúp nâng cao kỹ năng lập trình một cách bền vững. Đây cũng là cơ hội để rèn luyện tư duy logic, khả năng phân tích và sáng tạo, những yếu tố quan trọng trong nghề lập trình.
Hy vọng tài liệu này sẽ là người bạn đồng hành hữu ích, giúp các bạn tự tin giải quyết các bài toán lập trình C++, từ cơ bản đến nâng cao, và mở rộng khả năng ứng dụng kiến thức trong học tập, thi cử và dự án thực tế. Chúc các bạn học tập hiệu quả, yêu thích lập trình và gặt hái nhiều thành công trong năm học 2025-2026 và các chặng đường lập trình tiếp theo.
Lần cuối cùng xin chúc các bạn thành công trong bài học này
Khóa học Python online từ cơ bản đến nâng cao
Trung tâm tin học Tấn Dân
⚠️ Nỗi Đau Người Dùng: Laptop Acer Hư Giữa Chừng – Cảm Giác Bất Lực!…
Bạn đang làm việc, học tập hay xem phim, bỗng Laptop HP tự tắt cái…
Bạn đang sử dụng laptop Acer bình thường, bỗng một ngày màn hình đen thui,…
✅ Kiểm tra kỹ – Báo đúng bệnh – Không lo bị chém giá BÁC…
Laptop Toshiba nổi tiếng với độ bền, hiệu năng ổn định và giá thành hợp…
Tin vui đặc biệt cho người dùng Dell Vostro! Bạn đang dùng laptop Dell Vostro…
This website uses cookies.
View Comments
Wow wonderful blog layout How long have you been blogging for you make blogging look easy The overall look of your site is great as well as the content
Your writing is a true testament to your expertise and dedication to your craft. I'm continually impressed by the depth of your knowledge and the clarity of your explanations. Keep up the phenomenal work!
Your blog is like a beacon of light in the vast expanse of the internet. Your thoughtful analysis and insightful commentary never fail to leave a lasting impression. Thank you for all that you do.
Your blog is a breath of fresh air in the often mundane world of online content. Your unique perspective and engaging writing style never fail to leave a lasting impression. Thank you for sharing your insights with us.
I loved as much as you will receive carried out right here The sketch is tasteful your authored subject matter stylish nonetheless you command get got an edginess over that you wish be delivering the following unwell unquestionably come further formerly again as exactly the same nearly very often inside case you shield this hike
Attractive section of content I just stumbled upon your blog and in accession capital to assert that I get actually enjoyed account your blog posts Anyway I will be subscribing to your augment and even I achievement you access consistently fast
Your blog is a breath of fresh air in the often stagnant world of online content. Your thoughtful analysis and insightful commentary never fail to leave a lasting impression. Thank you for sharing your wisdom with us.
I wanted to take a moment to commend you on the outstanding quality of your blog. Your dedication to excellence is evident in every aspect of your writing. Truly impressive!
Your writing is like a breath of fresh air in the often stale world of online content. Your unique perspective and engaging style set you apart from the crowd. Thank you for sharing your talents with us.
I loved as much as youll receive carried out right here The sketch is attractive your authored material stylish nonetheless you command get bought an nervousness over that you wish be delivering the following unwell unquestionably come more formerly again as exactly the same nearly a lot often inside case you shield this hike