Untitled
unknown
plain_text
2 years ago
3.7 kB
2
Indexable
Bai 3: #include <iostream> using namespace std; int main() { int so; cout << "Nhap so: "; cin >> so; if (so >= 0 && so <= 9) { cout << "So ban nhap lai: " << so << endl; } else { cout << "Khong doc duoc." << endl; } return 0; } Bai 4 : #include <iostream> #include <cctype> using namespace std; int main() { char a; cout << "Nhap chu: "; cin >> a; if (islower(a)) { a = toupper(a); } else if (isupper(a)) { a = tolower(a); } cout << "Sau khi doi : " << a << endl; return 0; } Bai 5 : #include <iostream> using namespace std; int main() { float a, b; cout << "Nhap a: "; cin >> a; cout << "Nhap b: "; cin >> b; if (a == 0) { if (b == 0) { cout << "PT vo so nghiem." << endl; } else { cout << "PT vo nghiem." << endl; } } else { float x = -b / a; cout << "Nghiem PT la x = " << x << endl; } return 0; } Bai 6: #include <iostream #include <cmath> using namespace std; int main() { float a, b, c; cout << "Nhap a: "; cin >> a; cout << "Nhap b: "; cin >> b; cout << "Nhap c: "; cin >> c; float delta = b * b - 4 * a * c; if (delta > 0) { float x1 = (-b + sqrt(delta)) / (2 * a); float x2 = (-b - sqrt(delta)) / (2 * a); cout << "Nghiem x1 = " << x1 << endl; cout << "Nghiem x2 = " << x2 << endl; } else if (delta == 0) { float x = -b / (2 * a); cout << "Nghiem kep x = " << x << endl; } else { cout << "PT khong coa nghiem" << endl; } return 0; } Bai 7 : #include <iostream> using namespace std; int main() { int a, b, c, d; cout << "Nhap a: "; cin >> a; cout << "Nhap b: "; cin >> b; cout << "Nhap c: "; cin >> c; cout << "Nhap d: "; cin >> d; int max = a; // đây là giả sử nghen if (b > max) { max = b; } if (c > max) { max = c; } if (d > max) { max = d; } cout << "So lon nhat la : " << max << endl; return 0; } Bai 9 : #include <iostream> #include <iomanip> using namespace std; int main() { float quangduong; float tongxeng = 0; cout << "Nhap quang duong di taxi (km): "; cin >> quangduong; if (quangduong <= 1) { tongxeng = 1500; } else if (quangduong <= 5) { tongxeng = 1500 + (quangduong - 1) * 13500; } else { tongxeng = 1500 + 4 * 13500 + (quangduong - 5) * 11000; } if (quangduong > 120) { // giam 10% float giamgia = tongxeng * 0.1; tongxeng -= giamgia; } cout << fixed << setprecision(2); cout << "Tong: " << tongxeng << " dong " << endl; return 0; } Bai 8 : #include <iostream> using namespace std; int main() { int a, b, c, d; cout << "Nhap a: "; cin >> a; cout << "Nhap b: "; cin >> b; cout << "Nhap c: "; cin >> c; cout << "Nhap d: "; cin >> d; int hoandoi; if (a > b) { hoandoi = a; a = b; b = hoandoi; } if (b > c) { hoandoi = b; b = c; c = hoandoi; } if (c > d) { hoandoi = c; c = d; d = hoandoi; } if (a > b) { hoandoi = a; a = b; b = hoandoi; } if (b > c) { hoandoi = b; b = c; c = hoandoi; } if (a > b) { hoandoi = a; a = b; b = hoandoi; } cout << "Ket qua: " << a << " " << b << " " << c << " " << d << endl; return 0; }
Editor is loading...