Vinh La Kiến

48 bundles
2 files8 months ago
2

Get next date

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
#include <iostream> using namespace std; int main() { int d = 28; int m = 32; int y = 2019; 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 ? 29 : 28; break; } /* if (maxDay > 0) { if (m == 12) { if (d == 31) { d = 1; m = 1; y++; } else { d++; } } else { if (d == maxDay) { d = 1; m++; } else { d++; } } } */ if (maxDay > 0) { if (d == maxDay) { if (m == 12) { d = 1; m = 1; y++; } else { d = 1; m++; } } else { d++; } } if (d == 1) { if (m == 1) { d = 31; m = 12; y--; } else { m--; switch (m) { case 1: case 3: case 5:case 7:case 8:case 10:case 12: d = 31; break; case 4: case 6: case 9: case 11: d = 30; break; case 2: d = isLeapYear ? 29 : 28; break; } } } else { d--; } return 0; }

Prime number

12345678910111213141516171819202122
#include <iostream> #include <cmath> using namespace std; int main() { int number = 1; /* bool isPrimeNumber = true; if (number == 1) isPrimeNumber = false; */ bool isPrimeNumber = number > 1; int sqrtNumber = sqrt(number); for (int i = 2; i < sqrtNumber; i++) { if (number % i == 0) { isPrimeNumber = false; break; } } return 0; }