㈠ 万年历(C语言编程)
#include<stdio.h>
#include<time.h>
int
leap
(int
year)//判断闰年
{
if(year%4==0&&year%100!=0||year%400==0)
return
1;
else
return
0;
}
int
days_month
(int
month,int
year)//判断月
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
return
31;
if(month==4||month==6||month==9||month==11)
return
30;
if(month==2&&leap(year)==1)
return
29;
else
return
28;
}
int
firstday(int
month,int
year)//判断年
{
int
w;
w=(1+2*month+3*(month+1)/5+year+year/4+year/400-year/100)%7+1;
return
w;
}
main()
{
//调用系统时间
time_t
tval;
struct
tm
*now;
tval
=
time(NULL);
now
=
localtime(&tval);
printf("现在时间:
%4d年
%d月
%02d日
%d:%02d:%02d\n",
now->tm_year+1900,
now->tm_mon+1,
now->tm_mday,
now->tm_hour,
now->tm_min,
now->tm_sec);
//调用结束
int
i,j=1,k=1,a,b,month,year;
b=days_month(now->tm_mon+1,now->tm_year+1900);
a=firstday
(now->tm_mon+1,now->tm_year+1900);
printf("
Sun
Mon
Tue
Wed
Thu
Fri
Sat
\n");
if(a==7)
{
for(i=1;i<=b;i++)
{
printf("%4d",i);
if(i%7==0)
{
printf("\n");
}
}
}
if(a!=7)
{
while
(j<=4*a)
{
printf("
");
j++;
}
for(i=1;i<=b;i++)
{
printf("%4d",i);
if(i==7*k-a)
{
printf("\n");
k++;
}
}
}
printf("\n");
}
㈡ 用c语言编程万年历
/*以下程序在TC2 中通过*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
void rili(int,int);
int runniansub(int);
int week(int,int,int);
int monthday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
struct date d;
getdate(&d);
printf("今天是:%d年 %d月 %d日\n",d.da_year,d.da_mon,d.da_day);
rili(d.da_year,d.da_mon-1);
system("pause");
return 0;
}
void rili(int year,int month)
{
int d,w,i,s,c,p;
char x;
while(month>11) {
month-=12;
year++;
}
while(month<0) {
year--;
month+=12;
}
if(runniansub(year)) monthday[1]=29;
printf("%d年%d月\n",year,month+1);
printf("S M T W T F S\n");
s=week(year,month+1,1);
for(i=0; i<3*s; i++ ) printf(" ");
c=s;
for(d=1;d<=monthday[month];d++) {
if(c>6) {
printf("\n");
c=0;
}
c++;
printf("%d",d);
printf("%s",(d<10)?" ":" ");
}
printf("\n");
printf("下月N,上月P,退出Q");
x=getch();
printf("%c\n",x);
if(x=='N' || x=='n') { rili(year,month+1); }
else if(x=='P' || x=='p') { rili(year,month-1); }
else { printf("感谢使用!88\n"); return;}
}
int runniansub(int year)
{
return ((year%4==0 && year%100!=0) || (year%4==0 && year%400==0));
}
int week(int y,int m,int d)
{
if((m==1)||(m==2)) {
m+=12;
y--;
}
return ((d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)+1)%7;
}
㈢ c语言万年历编程
http://..com/question/103429211.html
㈣ c语言 如何编程万年历高手来~~高分求救!!!
笨比 这都不会还学什么啊 小垃圾
㈤ C语言程序设计万年历怎么编写
#include <stdio.h>
int IsLeapYear(int);
main()
{
int i;
int day;
int year;
int temp;
int temp_i;
long int Year_days = 0;
int Year_Start = 1;
int Per_Year_Days;
int month_day[]={31,28,31,30,31,30,31,31,30,31,30,31,29};
printf("Please enter the year: ");
scanf("%d",&year);
while(Year_Start < year)
{
if( IsLeapYear( Year_Start ) )
Per_Year_Days = 366;
else
Per_Year_Days = 365;
Year_days = Year_days + Per_Year_Days;
Year_Start++;
}
for( temp = 1; temp <=12; temp++ )
{
switch( temp )
{
case 1:
printf(" January(%d)\n",year);
break;
case 2:
printf(" February(%d)\n",year);
break;
case 3:
printf(" March(%d)\n",year);
break;
case 4:
printf(" April(%d)\n",year);
break;
case 5:
printf(" May(%d)\n",year);
break;
case 6:
printf(" June(%d)\n",year);
break;
case 7:
printf(" July(%d)\n",year);
break;
case 8:
printf(" August(%d)\n",year);
break;
case 9:
printf(" September(%d)\n",year);
break;
case 10:
printf(" October(%d)\n",year);
break;
case 11:
printf(" November(%d)\n",year);
break;
case 12:
printf(" December(%d)\n",year);
break;
}
i = Year_days % 7;
printf("Mon Tue Wed Thu Fri Sat Sun\n");
if( i != 0 )
for( temp_i = 0; temp_i < i; temp_i++)
printf(" ");
day = 1;
if( IsLeapYear(year) && temp == 2)
while( day <= month_day[12] )
{
if( day >1 )
if( Year_days % 7 == 0 )
printf("\n");
if( day >= 10 )
printf("%d ",day);
else
printf("%d ",day);
Year_days++;
day++;
}
else
while (day <= month_day[temp-1])
{
if( day > 1 )
if( Year_days % 7 == 0 )
printf("\n");
if( day >=10 )
printf("%d ",day);
else
printf("%d ",day);
Year_days++;
day++;
}
printf("\n");
if( getch() == 'q' )
exit(0);
}
getch();
}
int IsLeapYear( int year )
{
if ((year %4 == 0) && (year % 100 != 0) ||
(year % 400 == 0) )
return 1;
else
return 0;
}
㈥ c语言万年历编程解释
首先从主函数入手
main()
{
int year,month; //初始化参数
printf("输入年和月份:"); //在屏幕上输入提示
scanf("%d%d",&year,&month); //输入年和月
show(year,month); //显示函数
}
然后进入show()函数中进行一系列的运算。
其实这个都挺简单的了,如果需要详细解答,加我。
㈦ 用C语言怎么编写万年历
C语言编写万年历的源代码如下:
#include <stdio.h>
int week(int y,int m,int d);
int main()
{
char wk[7][3] = {{"天"},{"一"},{"二"},{"三"},{"四"},{"五"},{"六"}};
int year, month, day, w;
scanf("%d %d %d", &year, &month, &day);
w = week(year, month, day);
printf("%d年%d月%d日 星期%s", year, month, day, wk[w]);
}
int week(int y,int m,int d)
{
static int r[13]={0,0,3,3,6,1,4,6,2,5,0,3,5};
int c,w;
y %= 400;
if ((y==0||y%4==0&&y%100!=0)&&m<3)
c = 5;
else
c = 6;
w = (y+y/4-y/100+r[m]+d+c)%7;
return w;
}
(7)c语言万年历编程扩展阅读
电子时钟C语言版的源代码如下:
#include<stdio.h>
#include<time.h>
#include<string.h>
int main()
{
char str[50];
time_t t;
struct tm *nt;
while(1)
{
system("cls");//清屏函数
t=time(NULL);
nt=localtime(&t);
strftime(str,50,"%Y-%m-%d %H:%M:%S “,nt);
printf("现在时刻:%s ",str);
}
getch();
return 0;
}
㈧ 用c语言编写万年历系统,编程求大神支招
#include<stdio.h>
main()
{
for(;;)
{
intnian,yue,a,b,m,c,_m=28;
longe;
printf("请输入年份:");
scanf("%d",&nian);
e=nian;
e=e-1;
e=(e*365+e/4)%7;
m=e;
if((nian%4==0)||(nian%100==0)&&(nian%400!=0))
_m++;
printf("%d年的日历:",nian);
for(yue=1;yue<=12;yue++)
{
if(yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||yue==12)
{
c=0;
printf(" ");
printf("%d月 ",yue);
printf("日一二三四五六 ");
for(b=1;b<=m;b++)
{
c++;
printf("");
}
for(a=1;a<=31;a++)
{
c++;
if(c%7-1==0&&c!=1)printf(" ");
if(a<10)printf("");
printf("%d",a);
m++;
if(m==7)
m=0;
}
printf(" ");
}
else
{
if(yue==4||yue==6||yue==9||yue==11||yue==2)
{
if(yue==2)
{
c=0;
printf(" ");
printf("%d月 ",yue);
printf("日一二三四五六 ");
for(b=1;b<=m;b++)
{
c++;
printf("");
}
for(a=1;a<=_m;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf(" ");
if(a<10)
printf("");
printf("%d",a);
m++;
if(m==7)
m=0;
}
printf(" ");
}
else
{
c=0;
printf(" ");
printf("%d月 ",yue);
printf("日一二三四五六 ");
for(b=1;b<=m;b++)
{
c++;
printf("");
}
for(a=1;a<=30;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf(" ");
if(a<10)
printf("");
printf("%d",a);
m++;
if(m==7)
m=0;
}
printf(" ");
}
}
}
}
}
}
㈨ 如何用C语言编一个万年历系统
#include "stdio.h" /* Required for MS-DOS use */
#define ENTER 0x1C0D /* Enter key */
int year, month, day;
static char *days[8] = {" ","Sunday ","Monday ","Tuesday ",
"Wednesday","Thursday ","Friday ","Saturday "};
struct TIMEDATE {
int year; /* year 1980..2099 */
int month; /* month 1=Jan 2=Feb, etc. */
int day; /* day of month 0..31 */
int hours; /* hour 0..23 */
int minutes; /* minute 0..59 */
int seconds; /* second 0..59 */
int hsecs; /* 1/100ths of second 0..99 */
char dateline[47]; /* date & time together */
};
static struct TIMEDATE today;
main()
{
char cmonth[3];
char cday[3];
char cyear[5];
double getdays();
double daynumb, numbnow;
int weekday, retcode, dayer, i;
dayer = datetime(&today);
clrscn();
for (i=0;i<3;++i)cmonth[i]='\0';
for (i=0;i<3;++i)cday[i]='\0';
for (i=0;i<5;++i)cyear[i]='\0';
putstr(5,8,14,"Enter date in MM DD YYYY format:");
while (retcode != ENTER)
{
retcode = bufinp(5,41,13,2,cmonth);
if (retcode != ENTER) retcode = bufinp(5,44,13,2,cday);
if (retcode != ENTER) retcode = bufinp(5,47,13,4,cyear);
}
year = atoi(&cyear);
month = atoi(&cmonth);
day = atoi(&cday);
daynumb = getdays(year, month, day);
numbnow = getdays(today.year, today.month, today.day);
weekday = weekdays(daynumb);
if (numbnow - daynumb == 0)
printf("\n\n%02d-%02d-%d is",month, day, year);
if (numbnow - daynumb > 0)
printf("\n\n%02d-%02d-%d was",month, day, year);
if (numbnow - daynumb < 0)
printf("\n\n%02d-%02d-%d will be",month, day, year);
printf(" a %s\n",days[weekday]);
} /* end MAIN */
/************************************************************
* GETDAYS - From integer values of year (YYYY), month *
* (MM) and day (DD) this subroutine returns a *
* double float number which represents the *
* number of days since Jan 1, 1980 (day 1). *
* This routine is the opposite of GETDATE. *
************************************************************/
double getdays(year, month, day)
int year, month, day;
{
int y,m;
double a,b,d, daynumb;
double floor(),intg();
/**********************************
** make correction for no year 0 **
**********************************/
if (year < 0) y = year + 1;
else y = year;
/*********************************************************
** Jan and Feb are months 13 and 14 in this calculation **
*********************************************************/
m = month;
if (month < 3)
{
m = m + 12;
y = y - 1;
}
/**************************
** calculate Julian days **
**************************/
d = floor(365.25 * y) + intg(30.6001 * (m + 1)) + day - 723244.0;
/**********************************************
** use Julian calendar if before Oct 5, 1582 **
**********************************************/
if (d < -145068.0) daynumb = d;
/*************************************
** otherwise use Gregorian calendar **
*************************************/
else
{
a = floor(y / 100.0);
b = 2 - a + floor(a / 4.0);
daynumb = d + b;
}
return(daynumb);
} /* end GETDAYS */
/********************************************************
* GETDATE - This routine takes a double float number *
* representing the number of days since Jan 1,*
* 1980 (day 1) and returns the year month and *
* day as pointer integers *
* This routine is the opposite of GETDAYS *
********************************************************/
getdate(numb)
double numb;
{
double a,aa,b,c,d,e,z;
double date;
date = numb;
z = intg(date + 2444239.0);
if (date < -145078.0) a = z;
else
{
aa = floor((z - 1867216.25) / 36524.25);
a = z + 1 + aa - floor(aa/4.0);
}
b = a + 1524.0;
c = intg((b - 122.1) / 365.25);
d = intg(365.25 * c);
e = intg((b - d) / 30.6001);
day = b - d - intg(30.6001 * e);
if (e > 13.5) month = e - 13.0;
else month = e - 1.0;
if (month > 2) year = c - 4716.0;
else year = c - 4715.0;
if (year < 1) --year;
return;
} /* end GETDATE */
/********************************************************
* WEEKDAYS - This routine takes a double float number *
* representing the number of days since Jan 1,*
* 1980 (day 1) and returns the day of the week*
* where 1 = Sunday, 2 = Tuesday, etc. *
********************************************************/
int weekdays(numb)
double numb;
{
double dd;
int day;
dd = numb;
while (dd > 28000.0) dd = dd - 28000.0;
while (dd < 0) dd = dd + 28000.0;
day = dd;
day = ((day + 1) % 7) + 1;
return(day);
}
/********************************************************
* FRACT - This routine takes a double float number *
* and returns the fractional part as a double *
* float number *
********************************************************/
double fract(numb)
double numb;
{
int inumb;
double fnumb;
while (numb < -32767) numb += 32767;
while (numb > 32767) numb -= 32767;
inumb = numb;
fnumb = inumb;
return(numb-fnumb);
} /* end FRACT */
/********************************************************
* FLOOR - This routine takes a double float number *
* and returns the next smallest integer *
********************************************************/
double floor(numb)
double numb;
{
double fract(), intg();
double out;
out = intg(numb);
if (numb < 0 && fract(numb) != 0) out -= 1.0;
return(out);
} /* end FLOOR */
/********************************************************
* INTG - This routine takes a double float number *
* and returns the integer part as a double *
* float number *
********************************************************/
double intg(numb)
double numb;
{
double fract();
return(numb - fract(numb));
} /* end INTG */
㈩ 万年历C语言编程全过程
#include<stdio.h>
#include<windows.h>
void main()
{
char ans;
do{
int year,month;//月份和年份
int days = 0;//月份总天数
int sum = 0;//天数总和
int first;//月份第一天
int month_sum[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
printf("请输入年份:");
scanf("%d",&year);
printf("请输入月份:");
scanf("%d",&month);
do
{
if(month < 1 || month > 12)
{
printf("输入错误。请重新输入:");
scanf("%d",&month);
}
else
{
break;
}
}while(1);
//判断离1990-1-1多少天。
for(int i = 1900; i < year; i++)
{
if(i % 4 == 0 && i % 100 != 0 || i % 400 == 0)
{
sum += 366;
}
else
{
sum += 365;
}
}
//判断当年是不是闰年
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
month_sum[1] = 29;
}
//将月份总天数和年份总天数加起来
for(i = 1; i < month; i++)
{
sum += month_sum[i-1 ];
}
sum += 1;
//算出月份的第一天
first = sum % 7;
//输入格式
printf("%d年%d月\n",year,month);
printf("\n------------------------------------------------------\n");
printf("日 一 二 三 四 五 六\n");
switch(first)
{
case 0:
break;
case 1:
printf(" ");
break;
case 2:
printf(" ");
break;
case 3:
printf(" ");
break;
case 4:
printf(" ");
break;
case 5:
printf(" ");
break;
case 6:
printf(" ");
break;
}
for(i = 1; i <= month_sum[month-1]; i++)
{
printf("%d",i);
if((first+i) % 7 == 0)
{
printf("\n");
}
else
{
printf("\t");
}
}
printf("\n");
printf("继续?(y):");
fflush(stdin);
ans = getchar();
system("cls");
if(ans != 'Y' && ans != 'y')
{
break;
}
}while(1);
}
刚刚做好的,望采纳,可以实现循环输入。
另:每月的第一天是距1900年的总天数除以7的余数来决定的,