Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void main () {
- int inMonth;
- int inYear;
- int inDay;
- int daysPassedFromStartOfYear = 0;
- int currMonth;
- printf("Enter year: ");
- scanf("%d", &inYear);
- printf("Enter month: ");
- scanf("%d", &inMonth);
- printf("Enter day: ");
- scanf("%d", &inDay);
- // Sum days of all months before the current month
- for (currMonth = 1; currMonth < inMonth; currMonth++) {
- daysPassedFromStartOfYear += GetDaysInMonth(inYear, currMonth);
- }
- // Add days passed this month
- daysPassedFromStartOfYear += inDay;
- printf("Days passed: %d\n", daysPassedFromStartOfYear);
- }
- int GetDaysInMonth(int year, int month) {
- int days = 0;
- switch( month ) {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12:
- days = 31;
- break;
- case 4:
- case 6:
- case 9:
- case 11:
- days = 30;
- break;
- case 2:
- if (year % 4 == 0)
- days = 29;
- else
- days = 28;
- break;
- default:
- days = 0;
- break;
- }
- return days;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement