❶ 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语言课程设计 万年历
额。写过,我去找找
#include<stdio.h>
void PrintMonthCalender(int startDay,int days);/*函数原型*/
int GetWeekDay(int year,int month);/*函数原型*/
int GetMonthDays(int year,int month);/*函数原型*/
main()
{
int month,year;/*定义变量*/
printf("input the year and month<YYYY-MM>:");
scanf("%d-%d",&year,&month);/*读入变量*/
printf("\t\t\t%d-%d\n",year,month);
printf("Sun.\tMon.\tTue.\tWed.\tThu.\tFri.\tSat.\n");/*打印日历表头*/
PrintMonthCalender(GetWeekDay(year,month),GetMonthDays(year,month));/*调用函数子程序,打印出某年某月日历*/
return 0;
}
/*定义打印日历子程序*/
void PrintMonthCalender(int startDay,int days)
{
int k=0,n=1;
while(k<startDay)
{
printf(" \t");
k++;
}
if(k==startDay&&k!=6)
{
printf("%d\t",n);
k++;
n++;
}
else if(k==startDay&&k==6)
{
printf("%d\n",n);
k++;
n++;
}
while(n<days)
{
if(k%7==6)
{
printf("%d\n",n);
k++;
n++;
}
else
{
printf("%d\t",n);
k++;
n++;
}
}
if(n=days)
{
printf("%d\n",n);
n++;
}
}
/*定义求某月一号为周几子程序*/
int GetWeekDay(int year,int month)
{
int GetMonthDays(int year,int month);
int n,WeekDay,days;
days=(year-1)*365+(year-1)/400+(year-1)/4-(year-1)/100;
for(n=1;n<month;++n)
days=days+GetMonthDays(year,n);
WeekDay=(days+1)%7;
return WeekDay;
}
/*定义求某年某月的天数子程序*/
int GetMonthDays(int year,int month)
{
int MonthDays;
if((year%4==0&&year%100!=0)||year%400==0)
{
if(month==4||month==6||month==9||month==11)
MonthDays=30;
else if(month==2)
MonthDays=29;
else
MonthDays=31;
}
else
{
if(month==4||month==6||month==9||month==11)
MonthDays=30;
else if(month==2)
MonthDays=28;
else
MonthDays=31;
}
return MonthDays;
}
❸ 跪求~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" void main() { int year,month,day,sum=0,h=0,i,week; char answer; printf("*********************欢迎使用万年历**********************\n"); do { fflush(stdin); printf("请输入年份:"); scanf("%d",&year); printf("请输入月份:"); scanf("%d",&month); switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: day=31; break; case 4: case 6: case 9: case 11: day=30; break; case 2: day=28; if(year%4==0 && year%100!=0 || year%400==0) { day+=1; break; } } for(i=1900;i<year-1;i++) { if(year%4==0 && year%100!=0 || year%400==0) { sum+=366; } else { sum+=365; } } for(i=1;i<=month-1;i++) { switch(i) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: sum+=31; break; case 4: case 6: case 9: case 11: sum+=30; break; case 2: sum+=28; if(year%4==0 && year%100!=0 || year%400==0) { sum+=1; break; } } } week=sum%7+1; printf("星期天\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n"); if(week!=7) { for(i=1;i<=week;i++) { printf(" \t"); h++; } } for(i=1;i<=day;i++) { printf("%d\t",i); h++; if(h==7) { printf("\n"); h=0; } } fflush(stdin); printf("\n是否继续:(y/n):"); scanf("%c",&answer); } while(answer=='y'); } 呵呵 不好意思 可能没你要求那么完善 但是你说的基本已经给你搞定 其他的楼主修改一下即可!!
❺ 用C语言制作万年历
TC 2.0
/* welcome to use the WanNianLi system!
Copyright @ 2005 KongXinCai All rights reserved!:):):)*/
#include<stdio.h>
#include<stdlib.h>
char* month_str[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char* week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int IsLeapYear(int year) /*find out the year is leap year or not*/
{
if((year%4==0&&year%100!=0)||(year%400==0))
return 1;
else
return 0;
}
int month_day(int year,int month)
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(IsLeapYear(year)&&month==2)
return 29;
else
return(mon_day[month-1]);
}
int DaySearch(int year,int month,int day) /*search what day this day is*/
{
int c=0;
float s;
int m;
for(m=1;m<month;m++)
c=c+month_day(year,m);
c=c+day;
s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;
return ((int)s%7);
}
int PrintAllYear(int year)/*print the all year*/
{
int temp;
int i,j;
printf("\n\n%d Calander\n",year);
for(i=1;i<=12;i++)
{
printf("\n\n%s(%d)\n",month_str[i-1],i);
printf("0 1 2 3 4 5 6 \n");
printf("S M T W T F S \n\n");
temp=DaySearch(year,i,1);
for(j=1;j<=month_day(year,i)+temp;j++)
{
if(j-temp<=0)
printf(" ");
else if(j-temp<10)
printf("%d ",j-temp);
else
printf("%d ",j-temp);
if(j%7==0)
printf("\n");
}
}
return 0;
}
int main()
{
int option,da;
char ch;
int year,month,day;
printf("Copyright @ 2005 TianQian All rights reserved!:):):)");
printf("\n\nWelcome to use the WanNianLi system!\n");
while(1)
{
printf("\nPlease select the service you need:\n");
printf("\n1 Search what day the day is");
printf("\n2 Search whether the year is leap year or not");
printf("\n3 Print the calander of the whole year");
printf("\n4 Exit\n");
scanf("%d",&option);
switch(option)
{
case 1:
while(1)
{
printf("\nPlease input the year,month and day(XXXX,XX,XX):");
scanf("%d,%d,%d,%c",&year,&month,&day);
da=DaySearch(year,month,day);
printf("\n%d-%d-%d is %s,do you want to continue?(Y/N)",year,month,day,week[da]);
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 2:
while(1)
{
printf("\nPlease input the year which needs searched?(XXXX)");
scanf("%d",&year);
if(IsLeapYear(year))
printf("\n%d is Leap year,do you want to continue?(Y/N)",year);
else
printf("\n%d is not Leap year,do you want to continue(Y/N)?",year);
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 3:
while(1)
{
printf("\nPlease input the year which needs printed(XXXX)");
scanf("%d",&year);
PrintAllYear(year);
printf("\nDo you want to continue to print(Y/N)?");
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 4:
fflush(stdin);
printf("Are you sure?(Y/N)");
scanf("%c",&ch);
if(ch=='Y'||ch=='y')
exit(0);
break;
default:
printf("\nError:Sorry,there is no this service now!\n");
break;
}
}
return 0;
}
❻ c语言编写万年历
#include"stdio.h"
#include"stdlib.h"
#include"windows.h"
void welcome();
void getday(int year,int month);
void shuru();
void end();
long year;
long month;
void welcome()
{
printf("【万年历程序加载中");
for(int i=0;i<30;i++)
{
printf("★");
Sleep(100);
}
system("cls");
printf("【万年历程序加载中】\n");
Sleep(1000);
printf("☆~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~☆\n");
Sleep(1000);
printf(" ~~~谢谢使用【菠菜】制作的万年历~~~~\n");
Sleep(100);
printf("☆~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~☆\n");
Sleep(1000);
}
void end()
{
printf("【万年历关闭中");
for(int i=0;i<30;i++)
{
printf("★");
Sleep(100);
}
system("cls");
printf("【万年历关闭完成】\n");
Sleep(1000);
printf("☆~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~☆\n");
Sleep(1000);
printf(" ~~~谢谢使用【菠菜】制作的万年历~~~~\n");
Sleep(100);
printf("☆~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~☆\n");
Sleep(1000);
exit(0);
}
void shuru()
{
int a;
printf("☆~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~☆\n");
printf(" ≮欢迎使用万年历≯\n");
printf("☆~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~☆\n");
while(1)
{
printf("请输入年份:");
scanf("%d",&year);
if(year>0)
break;
else
{
printf("\n");
printf("你输入的年份有误,请重新输入\n"); } }
printf("\n");
while(1)
{
printf("请输入月份:");
scanf("%d",&month);
if(month>=1&&month<=12)
break;
else
{
printf("\n");
printf("你输入的月份有误,请重新输入\n"); } }
getday(year,month);
}
void getday(int year,int month)
{
int week; //星期几
int nowday=0; //该月前的总天数
long allday; //从公元1年起的总天数
int dayofmonth[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(year%4==0&&year%100!=0||year%400==0)
dayofmonth[2]=29;
for(int m=0;m<month;m++)
{
nowday=nowday+dayofmonth[m];
}
allday=nowday+year*365+year/4-year/100+year/400; //公元一年到现在用了多少天
week=allday%7; //求出这个月第一天是星期几
printf(" %d 年 %d 月\n",year,month);
printf("日 一 二 三 四 五 六\n");
for(int j=0;j<week;j++)
{
printf(" ");
}
for(int i=1;i<=dayofmonth[month];i++)
{
if(week==7)
{
printf("\n");
week=0; }
printf("%2d ",i);
week++; }
printf("\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
}
void main()
{
char a;
welcome();
while(1)
{
shuru();
printf("你还需要继续吗?<y ro n>");
fflush(stdin); //清空输入缓冲区,避免缓冲区内残存读取函数无法取走的内容!
scanf("%c",&a);
if(a=='n')
break;
}
end();
}
这个万年历比较好看哈!你可以试试这个?
❼ 用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语言课程设计-万年历
1.系统封面设计
内容:题目名称(中英文)、进入(中英文)、作者:***、时间:****-**-**
2.输入界面
内容:(1)密码口令输入及容错(3次)
(2)年份的输入及容错(3次)
3.日历计算设计
(1)求某月某日实行奇迹的函数(邱每月一号的星期数)。算法:(y-1)+(y-1)/4-(y-1)/100+(y-1)/400+c 得出S (y为年份,c为某月某日是这一年的第几天,S为总的天数)
(2)邱某月某日至这一年第几天的函数(求c) 闰年的算法: y/400==0 ?或y/400==0&&y/100!=0
根据(1)(2)求出每个月的日期
4、日历格式显示设计
要求:每屏显示4个月。
-------------------------------
❾ 用c语言编写万年历
写万年历程序,您需要先了解万年历的特点
下面是万年历的特点(复制粘贴的):
1. 平年365天(52周+1天),闰年366天(52周+2天)。平年2月28天,闰年2月29天。
由于公元1月1日设为星期六,故3月1日为星期三。 ——注意这个“三”
为使算法达到最简,故本算法以“星期”为计算单位。且选3月1日为基月。
2. 每400年整一闰,或每4年且不为百年的一闰。(原因:地球绕太阳一周的时间是365天5小时46秒,为了使一年的天数为整数,将一年的天数定为365天,余下的时间积累起来,四年就是23小时15分4秒,将近一天,把这一天加在某年的二月而成29天,该年称为闰年,其它年称为平年。但四年加一天又多用了44分56秒,这个数积满400年为三天。因此400年中只能有97个闰年,所以凡能被400整除,或不能被100整除但能被4整除的年份为闰年。)
所以百年%4=0闰或(年%4=0并且年<>0)闰。
3. 每 4年(3个平年+1个闰年)共208周+5天 ——注意这个“5天”
每百年共100*(208周+5天)-1天=5217周+5天 ——注意这个“5天”(整百年暂设为平年)
每400年共4*(5217周+5天)+1天(整400年闰)=20871周+0天——注意这个“0天”和“1天”(4个整百年只有一个闰年)
即400年一轮回!(原来万年历400年前是一家)
至于你说的日期和星期对齐,给你一点思路参考:每一行是7天,可以设定每一天占10个字符(同时上面的星期也得占满10个字符),假设本月第一天是星期4,那么在输出1之前需要先输出10×3个字符来占位,当输出星期天的日期之后换行,之后的就简单了
❿ C语言课程设计,万年历算星期几,只要随便说出公元几几年几月几日就可以马上算出是星期几. 阿里噶道/跪
万年历算星期几
只要随便说出公元几几年几月几日就可以马上算出是星期几.
只要计算出日的代码,月份代码,年份代码.三个加起来除以七的余数就是星期几,(如余数是三,则就是星期三).
日的代码计算:日的代码最简单,就是它本身,是几号就是几.
月份代码计算:月份代码也很简单,下面有十二个数:1 4 4 7 2 5 7 3 6 1 4 6,分别代表一至十二月份每个月的代码.比如,九月份的代码为6.(据来宾介绍,他是用逆推的方法,计算出这12个月份代码的,即知道某年某月某日是星期几,反过来推算月份代码.)
年份代码计算:年份代码相对比较复杂,先记住2000年对应的年份代码是4,这是基础代码,牢记即可.
假如大于2000年,比如2010年,则对应的年份代码是(2010-2000)÷4=2……2,再用基数代码4减去2倍的商加上余数再加1.即4-2×2+2+1=3,则2010年对应的年份代码为3.如果没有余数,即润年,则余数后面的1也不用加.比如2008年,对应的年份代码为0.
假如小于2000年,比如1991年,则对应的年份代码是(2000-1991)÷4=2……1,再用基数代码4加上2倍的商减去余数.即4+2×2-1=7,则1991年对应的年份代码为7.
再记住1个特殊情况,即润年的3到12月份到最后要加1.
1949年10月1日.
则(2000-1949)÷4=12……3,再4+2×12-3=25,年份代码计算结果为25,加上10月份的代码1,再加上日的代码1,等于27.再除以七的余数为6,则这一天为星期六.