STDIO Developer

20 bundles
1 file3 months ago
2

Tính ngày kế tiếp có sử dụng switch-case

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
#include <iostream> using namespace std; int main() { int d = 1; int m = 1; int y = 2008; bool isValid = false; bool isLeapYear = y % 400 == 0 || (y % 4 == 0 && y % 100 != 0); int maxDay = 0; switch (m) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: maxDay = 31; break; case 4: case 6: case 9: case 11: maxDay = 30; break; case 2: maxDay = isLeapYear == true ? 29 : 28; break; } if (d == maxDay) { if (m == 12) { d = 1; m = 1; y++; } else { m++; d = 1; } } else { d++; } cout << d << " " << m << " " << y; return 0; }