Posted By

ideabrian on 04/01/10


Tagged

month days in


Versions (?)

function days in month


 / Published in: C
 

  1. int days_in_month(int month) {
  2. const int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  3. switch (month) {
  4. case 1:
  5. printf("January has %d days\n", days[month]);
  6. break;
  7. case 2:
  8. printf("February usually has %d days\n", days[month]);
  9. break;
  10. case 3:
  11. printf("March has %d days\n", days[month]);
  12. break;
  13. case 4:
  14. printf("April has %d days\n", days[month]);
  15. break;
  16. case 5:
  17. printf("May has %d days\n", days[month]);
  18. break;
  19. case 6:
  20. printf("June has %d days\n", days[month]);
  21. break;
  22. case 7:
  23. printf("July has %d days\n", days[month]);
  24. break;
  25. case 8:
  26. printf("August has %d days\n", days[month]);
  27. break;
  28. case 9:
  29. printf("September has %d days\n", days[month]);
  30. break;
  31. case 10:
  32. printf("October has %d days\n", days[month]);
  33. break;
  34. case 11:
  35. printf("November has %d days\n", days[month]);
  36. break;
  37. case 12:
  38. printf("December has %d days\n", days[month]);
  39. break;
  40. default:
  41. printf("Hmmm.. that month wasn't programmed in.\n");
  42. break;
  43. } // end switch
  44.  
  45. return days[month];
  46. } // end days_in_month

Report this snippet  

You need to login to post a comment.