Skip to content

Instantly share code, notes, and snippets.

@duyet
Created March 23, 2014 05:18
Show Gist options
  • Save duyet/9719124 to your computer and use it in GitHub Desktop.
Save duyet/9719124 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main()
{
int day, month, max_day;
do {
printf("Nhap ngay, thang: ");
scanf("%d%d", &day, &month);
if (month < 0 || month > 12) {
printf("Nhap thang khong hop le (1-12)!\n");
continue;
}
switch (month) {
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
max_day = 31;
break;
case 2: max_day = 28; break;
default: max_day = 30;
}
if (day < 0 || day > max_day) {
printf("Ngay khong hop le (1-31)!\n");
continue;
}
if (day >= max_day) {
day = 1;
month++;
if (month > 12) month = 1;
} else {
day++;
}
printf("Ngay tiep theo: %d/%d", day, month);
break;
} while (1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment