将第一个程序写入第二个程序的void printYearCalendar中,使第一个程序为第二个程序的一个功能
#include <stdio.h>
// 函数声明
void printMenu();
void calculateFutureDate();
void printYearCalendar(int year);
void printMonthCalendar(int year, int month);
int main() {
int choice;
do {
printMenu();
printf("请输入您的选择(1-3),或者输入其他数字退出程序:");
scanf("%d", &choice);
switch(choice) {
case 1:
calculateFutureDate();
break;
case 2: {
int year;
printf("请输入年份:");
scanf("%d", &year);
printYearCalendar(year);
break;
}
case 3: {
int year, month;
printf("请输入年份和月份:");
scanf("%d %d", &year, &month);
printMonthCalendar(year, month);
break;
}
default:
printf("谢谢使用,再见!\n");
return 0;
}
} while(1);
return 0;
}
// 打印功能菜单
void printMenu() {
printf("==== 日历问题 ====\n");
printf("1. 计算未来天数和星期\n");
printf("2. 打印年历\n");
printf("3. 打印月历\n");
}
void calculateFutureDate() {
// 在这里实现计算未来天数和星期的功能
}
// 打印某年的日历
void printYearCalendar(int year) {
}
void printMonthCalendar(int year, int month) {
}
#include <stdio.h>
#include <time.h>
#include <math.h>
int isLeapYear(int year)
{
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int daysInMonth(int month, int year)
{
switch (month)
{
case 2: return isLeapYear(year) ? 29 : 28;
case 4: case 6: case 9: case 11: return 30;
default: return 31;
}
}
int caile(int y1,int m)
{
int a,b,c,w;
if(m==1||m==2)
{
m=+12,y1-=1;
}
c=y1/100,b=y1%100;
w=(floor(c/4)+floor(b/4)+2*c-floor(26*(m+1)/10));
w=(w+777)%7;
return w;
}
void printMonth1(int caile1,int caile2,int caile3, int month1,int month2,int month3,int year1,int month4)
{
int caile[3],i,j,l,day[3],month[3];
caile[1]=caile1,caile[2]=caile2,caile[3]=caile3;
month[1]=month1,month[2]=month2,month[3]=month3;
day[1]=1,day[2]=1,day[3]=1;
if(month4==1)
{
printf("Jan Feb Mar");
}
else if(month4==4)
{
printf("Apr May Jun");
}
else if(month4==7)
{
printf("Jul Aug Set");
}
else
{
printf("Oct Nov Dec");
}
printf("\n");
for(j=1;j<4;j++)
{
printf(" Sun Mon Tue Wed Thu Fri Sat ");
}
printf("\n");
for(j=1;j<4;j++)
{
for (int i = 0; i < caile[j]; i++)
{
printf(" ");
}
for (day[j]=1; day[j] <= 30; day[j]++)
{
printf("%4d", day[j]);
if ((caile[j] + day[j]) % 7 == 0)
{
printf(" ");
break;
}
}
}
printf("\n");
for(l=2;l<7;l++)
{
for(j=1;j<=3;j++)
{
i=0;
for (day[j]=day[j]+1; day[j] <= 42; day[j]++)
{
if(day[j]<=month[j])
{
printf("%4d", day[j]);
i=i+1;