这两个程序如何组合啊
问下这个程序:#include "stdio.h"
#include "conio.h"
void main()
{
int leap_year(int y);
int count_leap(long year);
int monthdays(int month,long year);
void monthprint(long year,int month);
int month=0;
long year=0;
char choose;
do
{printf ("\n\nPlease input one integer number as 'year'(0~999999):\n");
scanf ("%ld",&year);
if (year<0||year>999999) printf ("WANNING:ERROR,please input again!");
}
while (year<0||year>999999);
printf ("\n\n");
do
{printf ("please input the month(1~12)\n\n");
scanf ("%d",&month);
if (month<=0||month>12) printf ("WANNING:ERROR,please input again!");
}
while (month<=0||month>12);
printf ("\n\n\n");
printf("\t\t\t\t%ld\t%d\n\n",year,month);
printf
("\n********************************************************************************\n");
printf("\t\t Sun\t Mon\t Tue\t Wen\t Thu\t Fri\t Sat\n");
monthprint(year,month);
printf("\n\n");
choose=getchar();
printf("Continue?(y/n):\n\n");
scanf("%c",&choose);
if (choose=='y'||choose=='Y') main(); /*main函数调用main函数本身*/
}
int leap_year(int y)//判断闰年
{ int i;
if (y%4==0&&y%100!=0||y%400==0) i=1;
else i=0;
return i;
}
int count_leap(long year)
{
int i=0,j,min,max;
if(year>2006) {min=2006;max=year;}
else {min=year+1;max=2006;}
for(j=min;j<max;j++)
if(leap_year(j)) i++;
return i;
}
int monthdays(int month,long year)
{
int sum=0,i,j;
if(year>=2006)
{ static int t[12]={31,0,31,30,31,30,31,31,30,31,30,31};/*1~12月的每月天数*/
j=month-1;
if(leap_year(year)) t[1]=29;
else t[1]=28;
for(i=0;i<j;i++)
sum=sum+t[i];
}
else
{ static int t1[12]={31,30,31,30,31,31,30,31,30,31,0,31}; /*12~1月的每月天数*/
j=12-month;
if(leap_year(year)) t1[10]=29;
else t1[10]=28;
for(i=0;i<=j;i++)
sum=sum+t1[i];
}
return sum;
}
void monthprint(long year,int month)
{
static int t[12]={31,0,31,30,31,30,31,31,30,31,30,31};
int i,y,weekday=0;
long days=0;
if(leap_year(year)) t[1]=29;
else t[1]=28;
y=t[month-1];
if(year>2006)
{
days=(year-2006)*365+count_leap(year)+monthdays(month,year);
weekday=days%7;
}
else if(year<2006)
{days=(2005-year)*365+count_leap(year)+monthdays(month,year);
weekday=7-days%7;
}
else
{days=monthdays(month,year);weekday=days%7;}
for (i=1;i<=weekday+2;i++) /*由于上一行打印星期的时候空2个制表位,所以weekday要加2*/
printf ("\t");
for (i=1;i<=y;i++)
{if ((i+weekday-1)%7==0) printf ("\n\n\t\t%3d\t",i);
else printf ("%3d\t",i);};
printf
("\n********************************************************************************\n\n");
}
和这一个程序:
#ifndef _TM_DEFINED
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
#define _TM_DEFINED
#endif
#include <iostream.h>
#include <time.h>
int main(void)
{
struct tm *local;
long t;
time(&t);
cout << "The Calendar Time now is:" << t << endl ;
local = localtime(&t);
local->tm_year = local->tm_year + 1900;
local->tm_mon ++;
cout << "今天是: " << local->tm_year << "年" << local->tm_mon
<< "月" << local->tm_mday << "日" << "星期" << local->tm_wday
<<"当前的时间是:"<< local->tm_hour
<< "时" << local->tm_min << "分" << local->tm_sec <<"秒"
<< endl;
return 0;
}
怎么进行组合成一个程序,我怎么试都不行啊!
各位帮个忙。