Write a C program using if else statements and user defined functions Given a mo
ID: 3674078 • Letter: W
Question
Write a C program using if else statements and user defined functions
Given a month (1 – 12) and a day (1 – 29/30/31 maximum depends on the month) in the current year (2016) determine the equivalent date on the lunar calendar. The conversion of the Gregorian (2016) dates to lunar can be found here: http://www.hko.gov.hk/gts/time/calendar/pdf/2016e.pdf
Example outputs -
1.
Enter month number: 1
Enter day number: 8
Day 1 of the first lunar month of the new year
2.
Enter month number: 1
Enter day number: 1
Day 22 of the 11th lunar month of the previous month
3.
Enter month number: 1
Enter day number: 10
Day 1 of the 12th lunar month of the previous year
4.
Enter month number: 2
Enter day number: 29
Day 22 of the 1st lunar month of the new year
Explanation / Answer
i) From my understanding, The program suppose to decrease 8 days from the given date.
ii) check the if the year is leap year.
iii) if the date is greater than 7 it is important to check number of days the previous month has
printf (" Enter date");
Scanf (%d, &date);
if month= 2 or 4 or 6 or 8 or 9 or 11 or 1
31_month_flag =1 ;
if (date> 8)
{
lun_date = date - 8;
lun_month = month;
lun_year = year;
Printf( " lunar date is %d - %d - %d", lun_date, lun_month, lun_year");
}
else
{
if month = 3
{
if leap_flag = 1
date = 8- date
lun_date = 29 - date
lun_month = 1
lun_year = year
else
date = 8- date
lun_date = 28 - date
lun_month = 1
lun_year = year
}
lun_date = 31 - date
lun_month = month -1
lun_year = year
}
else
lun_date = 31 - date
lun_month = month -1
lun_year = year
}
if month = 1
{
date = 8- date
lun_date = 31 - date
lun_month = 12
lun_year = year -1
}
Printf( " lunar date is %d - %d - %d", lun_date, lun_month, lun_year");
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.