fork download
  1. #include <stdio.h>
  2.  
  3. void main()
  4. {
  5. int day, mth, year, dperm;
  6.  
  7. printf("Type the date using the following format: day/month/year \n");
  8. scanf("%d/%d/%d", &day, &mth, &year);
  9.  
  10. if (year >= 1 && year % 400 != 0 && year % 4 != 0)
  11. {
  12. int dperm[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31 , 30, 31 };
  13. if (mth >= 1 && mth <= 12)
  14. {
  15. if (day == dperm[mth])
  16. {
  17. printf("valid date \n");
  18. }
  19. else
  20. {
  21. printf("invalid date \n");
  22. }
  23. }
  24. else
  25. {
  26. printf("invalid date (incorrect month) \n");
  27. }
  28. }
  29. else if (year >= 1 && year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
  30. {
  31. int dperm[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31 , 30, 31 };
  32.  
  33. if (mth >= 1 && mth <= 12)
  34. {
  35. if(day == dperm[mth])
  36. {
  37. printf("valid date \n");
  38. }
  39. else
  40. {
  41. printf("invalid date \n");
  42. }
  43. }
  44. else
  45. {
  46. printf("invalid date (incorrect month) \n");
  47. }
  48. }
  49. else
  50. {
  51. printf("invalid date (incorrect year) \n");
  52. }
  53. return 0;
  54. }
  55.  
Runtime error #stdin #stdout 0s 2172KB
stdin
Standard input is empty
stdout
Type the date using the following format: day/month/year 
invalid date (incorrect month)