c語言萬年歷設計
❶ 設計一個萬年歷c語言
|#include<stdio.h>
int getDays(int year,int month,int day);
int isLeapYear(int year);
int getMonthDays(int year,int month);
void main()
{
int year,month,day;
int i,days=0,weekday,monthdays;
int calendar[42]={0};
char *p[7]={"SUN","MON","TUE","WES","THU","FRI","SAT"};
scanf("%d-%d-%d",&year,&month,&day);
for(i=1980;i<year;i++)
{
if(isLeapYear(i))
days+=366;
else days+=365;
}
days+=getDays(year,month,1);
weekday=(days+1)%7;
//printf("%d",weekday);
monthdays=getMonthDays(year,month);
for(i=0;i<monthdays;i++)
{
calendar[weekday+i]=i+1;
}
for(i=0;i<7;i++)
{
printf("%s ",p[i]);
}
printf("\n");
for(i=0;i<42;i++)
{
if(calendar[i]!=0)
{
if(calendar[i]==day)
printf("[%d]",day);
else printf("%3d ",calendar[i]);
}
else printf(" ");
if((i+1)%7==0)
printf("\n");
}
}
int getMonthDays(int year,int month)
{
int days;
switch(month)
{
case 1:case 3:case 5:case 7:case 8:case 10:case 12:days=31;break;
case 4:case 6:case 9:case 11:days=30;break;
case 2:if(isLeapYear(year))days=29;
else days=28;
}
return days;
}
int getDays(int year,int month,int day)
{
int days=0;
switch(month)
{
case 12:days+=30;
case 11:days+=31;
case 10:days+=30;
case 9 :days+=31;
case 8 :days+=31;
case 7 :days+=30;
case 6 :days+=31;
case 5 :days+=30;
case 4 :days+=31;
case 3 :if(isLeapYear(year))days+=29;
else days+=28;
case 2 :days+=31;
}
days+=day;
return days;
}
int isLeapYear(int year)
{
if((year%400==0)||((year%4==0)&&(year%100!=0)))
{
return 1;
}
else
{
return 0;
}
}
❷ 請使用C語言設計一個萬年歷和記事本,急!
我來回答了,把分給我吧!
❸ C語言編寫萬年歷實驗設計
網上找的部分帶我,我又修改了一下,現在基本滿足lz的要求。
手頭沒有Wintc用vc測的,不過沒用到什麼vc特有的東西,應該可以的。
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void DayOfWeek()
{
int rtnDay;
int y,m,d;
char ch;
while (1)
{
printf("請輸入年月日(xxxx,xx,xx): ");
scanf("%d,%d,%d", &y, &m, &d);
fflush(stdin);
rtnDay = (3*y-(7*(y+(m+9)/12))/4+(23*m)/9+d+17-((y+(m<3?-1:0))/100+1)*3/4) % 7;
printf("%04d年%02d月%02d日 是 星期%d\n", y, m, d, rtnDay?rtnDay:7);
printf("繼續查詢(y/n)");
ch = getchar();
if(ch != 'y' && ch != 'Y')
break;
}
}
void GetMonth(int D, int md, int n)
{
int N ,m,d,y,c,Wd;
int i,maxday,i1;
if(md>=13||md<=0)
printf("HAVE WRONG!");
else
{
for(i1=0;;md++,i1++)
{
if(md==0)
{
md=12;
D-=1;
}
else
if(md==13)
{
md=1;
D+=1;
}
m=md;
printf("\n============%d,%2d============\n",D,md);
if(0<m&&m<=12)
{
switch(m)
{
case 1:maxday=31;break;
case 2:if(D%4==0&&D%100!=0||D%400==0)
maxday=29;
else
maxday=28;
break;
case 3:maxday=31;break;
case 4:maxday=30;break;
case 5:maxday=31;break;
case 6:maxday=30;break;
case 7:maxday=31;break;
case 8:maxday=31;break;
case 9:maxday=30;break;
case 10:maxday=31;break;
case 11:maxday=30;break;
case 12:maxday=31;break;
default:printf("HAVE WRONG");
}
if(0<m&&m<=2)
{
N=D-1;
m=m+10;
}
else
{
N=D;
m=m-2;
}
c=N/100;
y=N%100;
Wd=((1+(13*m-1)/5+y+y/4+c/4-2*c)%7+7)%7;
printf(" SUN MOU TUE WED TUR FRI SAT\n");
for(i=0;i<Wd;i++)
printf("%4c",' ');
for(d=1;d<=maxday;d++)
{
printf("%4d",d);
Wd=(Wd+1)%7;
if(Wd==0)
printf("\n");
}
}
else
printf("HAVE WRONG!");
if(i1==n)
break;
}
}
}
void MonthOfYear()
{
char ch;
int y, m;
while (1)
{
printf("請輸入年月(xxxx,xx): ");
scanf("%d,%d", &y, &m);
fflush(stdin);
GetMonth(y, m, 0);
printf("\n繼續查詢(y/n)");
ch = getchar();
if(ch != 'y' && ch != 'Y')
break;
}
}
void GetYear()
{
char ch;
int y;
while (1)
{
printf("請輸入年: ");
scanf("%d", &y);
fflush(stdin);
GetMonth(y, 1, 11);
printf("\n繼續查詢(y/n)");
ch = getchar();
if(ch != 'y' && ch != 'Y')
break;
}
}
int main()
{
char ch;
while(1)
{
system("cls");
printf("1.查詢星期\n");
printf("2.查詢月份\n");
printf("3.顯示一年\n");
printf("4.退出程序\n");
ch = getchar();
fflush(stdin);
switch(ch)
{
case '1':
DayOfWeek();
break;
case '2':
MonthOfYear();
break;
case '3':
GetYear();
break;
case '4':
printf("是否退出(y/n)");
ch = getchar();
fflush(stdin);
if(ch == 'y' || ch == 'Y')
exit(0);
break;
}
}
}
❹ 用C語言編寫萬年歷,急!
已經編譯運行確認過。
#INCLUDE <STDIO.H>
#INCLUDE <STDLIB.H>
INT LEAP(INT); /*判斷是否為閏年*/
INT MD(INT M,INT Y); /*返回本月的天數*/
VOID PRTWEEK(VOID); /*輸出表頭*/
INT FW(INT M,INT Y); /*返回本月一號是星期幾*/
VOID PRTMONTH(INT M); /*輸出月份表頭*/
INT MAIN(VOID)
{
INT Y,M,I,TEST,WEEK;
PRINTF("PLEASE IMPORT YEAR OF YOU WANT TO SELECT : ");
SCANF("%D",&Y);
FOR (M=1; M<=12; M++) {
TEST=1;
PRTMONTH(M);
PRTWEEK();
WEEK=FW(M,Y);
IF (WEEK!=6)
FOR (I=0; I<=WEEK; I++) {
PUTCHAR('\T');
TEST++;
}
FOR (I=1; I<=MD(M,Y); I++,TEST++) {
PRINTF("%D\T",I);
IF (TEST%7==0) {
PUTCHAR('\N');
}
}
PUTCHAR('\N');
SYSTEM("PAUSE");//暫停,以便觀察輸出
}
RETURN 0;
}
INT LEAP(INT Y)
{
RETURN (Y%4==0&&Y%100||Y%400==0)?1:0;
}
INT MD(INT M,INT Y)
{
INT D;
SWITCH (M) {
CASE 1:
CASE 3:
CASE 5:
CASE 7:
CASE 8:
CASE 10:
CASE 12:D=31;BREAK;
CASE 4:
CASE 6:
CASE 9:
CASE 11:D=30;BREAK;
CASE 2:D=LEAP(Y)?29:28;BREAK;
}
RETURN D;
}
VOID PRTWEEK(VOID)
{
PRINTF("%S\T%S\T%S\T%S\T%S\T%S\T%S\T\N","SUN","MON","TUE","WED","THUR","FRI","SAT");
}
INT FW(INT M,INT Y)
{
INT F;
IF (M<3) {
M+=12;
Y--;
}
F=(1+2*M+3*(M+1)/5+Y+Y/4-Y/100+Y/400)%7;
RETURN F;
}
VOID PRTMONTH(INT M)
{
SWITCH (M) {
DEFAULT:
CASE 1:PUTS("===JANUARY===");BREAK;
CASE 2:PUTS("===FEBRUARY===");BREAK;
CASE 3:PUTS("===MARCH===");BREAK;
CASE 4:PUTS("===APRIL===");BREAK;
CASE 5:PUTS("===MAY===");BREAK;
CASE 6:PUTS("===JUNE===");BREAK;
CASE 7:PUTS("===JULY===");BREAK;
CASE 8:PUTS("===AUGUST===");BREAK;
CASE 9:PUTS("===SEPTEMBER===");BREAK;
CASE 10:PUTS("===OCTOBER===");BREAK;
CASE 11:PUTS("===NOVEMBER===");BREAK;
CASE 12:PUTS("===DECEMBER===");BREAK;
}
❺ c語言程序設計 萬年歷報告書
||#include <stdio.h>
void main()
{
int year,month,day,days,sum,i,n=0,a;
char c;
redo: printf("請輸入年/月/日(例如:2010/1/1):\n");
scanf("%d/%d/%d",&year,&month,&day);
if(month==1&&(day>=32||day<=0))
{
printf("輸入有誤!1月只能有31天!\n");
goto redo;
}
if(month==2)
{
if((year%400==0)||(year%4==0&&year%100!=0))
{
if(day>=30||day<=0)
{
printf("輸入有誤!%d年是閏年,二月只能有29天!\n",year);
goto redo;
}
}
else if(day>=29||day<=0)
{
printf("輸入有誤!%d年是平年,二月只能有28天!\n",year);
goto redo;
}
}
if(month==3&&(day>=32||day<=0))
{
printf("輸入有誤!3月只能有31天!\n");
goto redo;
}
if(month==4&&(day>=31||day<=0))
{
printf("輸入有誤!4月只能有30天!\n");
goto redo;
}
if(month==5&&(day>=32||day<=0))
{
printf("輸入有誤!5月只能有31天!\n");
goto redo;
}
if(month==6&&(day>=31||day<=0))
{
printf("輸入有誤!6月只能有30天!\n");
goto redo;
}
if(month==7&&(day>=32||day<=0))
{
printf("輸入有誤!7月只能有31天!\n");
goto redo;
}
if(month==8&&(day>=32||day<=0))
{
printf("輸入有誤!8月只能有31天!\n");
goto redo;
}
if(month==9&&(day>=31||day<=0))
{
printf("輸入有誤!9月只能有30天!\n");
goto redo;
}
if(month==10&&(day>=32||day<=0))
{
printf("輸入有誤!10月只能有31天!\n");
goto redo;
}
if(month==11&&(day>=31||day<=0))
{
printf("輸入有誤!11月只能有30天!\n");
goto redo;
}
if(month==12&&(day>=32||day<=0))
{
printf("輸入有誤!12月只能有31天!\n");
goto redo;
}
if(month>=1&&month<=12)
{
if(year%400==0||(year%4==0&&year%100!=0))
printf("%d年是閏年。\n",year);
else printf("%d年是平年。\n",year);
}
if(year>=1901) goto loop1;
else goto loop2;
loop1: for(i=1901;i<year;i++)
{
if(i%400==0||(i%4==0&&i%100!=0))
n++;
}
days=(year-1901-n)*365+n*366;
switch(month)
{
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=59;break;
case 4:sum=90;break;
case 5:sum=120;break;
case 6:sum=151;break;
case 7:sum=181;break;
case 8:sum=212;break;
case 9:sum=243;break;
case 10:sum=273;break;
case 11:sum=304;break;
case 12:sum=334;break;
default:printf("一年內只能有12個月!請重新輸入!\n");goto redo;
}
a=sum+day+days;
if((year%400==0||(year%4==0&&year%100!=0))&&(month>=3))
a++;
if(a%7==1) printf("%d年%d月%d日是星期二。\n",year,month,day);
if(a%7==2) printf("%d年%d月%d日是星期三。\n",year,month,day);
if(a%7==3) printf("%d年%d月%d日是星期四。\n",year,month,day);
if(a%7==4) printf("%d年%d月%d日是星期五。\n",year,month,day);
if(a%7==5) printf("%d年%d月%d日是星期六。\n",year,month,day);
if(a%7==6) printf("%d年%d月%d日是星期天。\n",year,month,day);
if(a%7==0) printf("%d年%d月%d日是星期一。\n",year,month,day);
goto label;
loop2: for(i=1900;i>year;i--)
{
if(i%400==0||(i%4==0&&i%100!=0))
n++;
}
days=(1900-year-n)*365+n*366;
switch(month)
{
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=58;break;
case 4:sum=90;break;
case 5:sum=120;break;
case 6:sum=151;break;
case 7:sum=181;break;
case 8:sum=212;break;
case 9:sum=243;break;
case 10:sum=273;break;
case 11:sum=304;break;
case 12:sum=334;break;
default:printf("一年內只能有12個月!請重新輸入!\n");goto redo;
}
if(year%400==0||(year%4==0&&year%100!=0))
a=366-(day+sum)+days;
else a=365-(day+sum)+days;
if((year%400==0||(year%4==0&&year%100!=0))&&(month>=3))
a--;
if(a%7==0) printf("%d年%d月%d日是星期一。\n",year,month,day);
if(a%7==1) printf("%d年%d月%d日是星期天。\n",year,month,day);
if(a%7==2) printf("%d年%d月%d日是星期六。\n",year,month,day);
if(a%7==3) printf("%d年%d月%d日是星期五。\n",year,month,day);
if(a%7==4) printf("%d年%d月%d日是星期四。\n",year,month,day);
if(a%7==5) printf("%d年%d月%d日是星期三。\n",year,month,day);
if(a%7==6) printf("%d年%d月%d日是星期二。\n",year,month,day);
label: printf("Do you want to continue?Y/N:");
getchar();
c=getchar();
if(c=='Y'||c=='y')
{
n=0;
goto redo;
}
}
❻ 求大神!C語言編寫《萬年歷的設計》。。。
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
#include<ctime>
usingnamespacestd;
intmain()
{
tm*year1;
tm*month1;
time_tt;
t=time(0);
year1=localtime(&t);
month1=localtime(&t);
intf;//元月一抄日是星期幾
intoffset;//元月一日是星期幾
intday=1;//第一天
intyear;
intmonth;
intd;//一月一日到這個月天數
intg;//計算是周幾
......
要是滿意,請點贊,發源碼
❼ 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語言程序設計萬年歷
#include <stdio.h>
int leap (int year)
{if(year%4==0&&year%100!=0||%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; //判斷二月是29天還是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()
{int i,j=1,k=1,a,b,month,year;
printf("\n input month and year:\n");
scanf("%d%d",&month,&year); //輸入月和年
b=days_month(month,year);
a=firstday (month,year);
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語言程序設計~~~萬年歷
#include<stdio.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;
}
void main()
{
int i,j=1,k=1,a,b,month,year;
printf("input month and year:");
scanf("%d%d",&month,&year);
b=days_month(month,year);
a=firstday (month,year);
printf("\n******************************\n");
printf(" 公元%d年%2d月",year,month); printf("\n******************************\n");
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語言設計萬年歷
看看沒人幫你,我來幫你吧,以下是我新寫的,用了我自己原創的演算法,完全不同於網上的程序,等於說是專門為你量身定製的。奉上程序:
#include<stdio.h>
#include<windows.h>
char*NameOfMonth[12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char*WeekDay[7]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
intIsLeapYear(intyear)
{
if(year%4==0&&year%100!=0||year%400==0)
{
return1;//閏年返回1
}else
{
return0;//平年返回0
}
}
intDateCheck(intuYear,intuMonth,intuDay)//合法返回true,非法或超出范圍返回false
{
if(uYear<1901||uYear>9999||uMonth<1||uMonth>12||uDay<1||uDay>31)
{
return0;
}
if(uMonth==4||uMonth==6||uMonth==9||uMonth==11)
{
if(uDay>30)
{
return0;
}
}elseif(uMonth==2)
{
if(IsLeapYear(uYear))
{
if(uDay>29)
{
return0;
}
}else
{
if(uDay>28)
{
return0;
}
}
}
return1;
}
intGetDays(intyear,intmonth,intday)
{
intsum=0;
if(DateCheck(year,month,day)==0)
{
return-1;//日期有誤
}
if(year>=1901)
{
intX=(int)(year/100);//世紀數
intY=X-(int)(X/4);//如果按4年一閏來算,Y指的是比實際上多算的天數,在下面需要減去
if(month<=2&&month>0)
{
year--;//把1月、2月視為上一年的13月、14月(純粹為了計算需要)
month+=12;
}
sum=(int)(365.25*(year-1900))+(int)(30.6*(month+1))+day-Y-49;//以365.25(本來實際太陽年是365.2425天)來計算是為了計算按4年一閏的整數年總天數,加上月份天數再加上餘下天數,減掉多閏天數,再減掉一個偏差值(多加的)
//月份以30.6天的平均值計算。最後減去的49,是多加的一個月以及其餘相差天數的和,可得到1900年1月1日的積日為0
}
returnsum;//返回距離1900年1月1日的總天數(積日)
}
intGetDayOfMonth(intmonth,intyear)
{
inttmp_days=GetDays(year,month,1);//本月積日
intDayOfMonth=0;
month++;//下個月
if(month>12)
{
month=1;//遇到月份為12月的情況,月份為1,年份加1
year++;
}
DayOfMonth=GetDays(year,month,1);//下個月的積日
DayOfMonth-=tmp_days;//下月1日的總天數(距離1900年1月1日的積日)減去當前月1日的總天數
returnDayOfMonth;//返回當前月總天數
}
intShowCalendar(intyear,intmonth,intday)
{
inti,j,count;
intjiri=0;//積日
intdayofweek=0;//星期
if(DateCheck(year,month,day)==0)
{
printf("輸入日期有誤!
");//日期不合法或超出范圍,年歷從1901年開始
return0;
}
printf(" %d%s
",year,NameOfMonth[month-1]);
printf("--------------------------------------
");
printf("SunMonTueWedThuFriSat
");
printf("--------------------------------------
");
jiri=GetDays(year,month,1);//獲取距離1900年1月1日的總天數
dayofweek=(1+jiri)%7;//月首星期,因為1900年1月1日星期一
count=GetDayOfMonth(month,year);
for(i=0;i<dayofweek;i++)
{
printf("");//填充前面空格
}
for(i=1,j=dayofweek;i<=count;i++,j++)
{
if(i<10)
{
printf("%d",i);
}else
{
printf("%d",i);
}
if((j+1)%7==0)
{
if(i!=count)
{
printf("
");//滿7天,換行
}
}
}
printf("
--------------------------------------
");
return1;
}
intmain()
{
intyear,month,day,nChoise=0;
inttotaldays=0;
while(1)//主循環
{
printf("******************歡迎使用萬年歷********************
");
printf("$菜單$
");
printf("$1.閏年判斷2.星期計算$
");
printf("$$
");
printf("$3.月歷查詢4.列印整年日歷$
");
printf("$$
");
printf("****************************************************
");
printf("輸入對應的序號進行相關操作:Choise>");
scanf("%d",&nChoise);
switch(nChoise)
{
case1:
printf("請輸入要判斷的年份:Year>");
scanf("%d",&year);
if(year<1900||year>9999)
{
printf("輸入年份超出范圍!");
break;
}
if(IsLeapYear(year)==1)
{
printf("%d年是閏年!
",year);
}else
{
printf("%d年不是閏年!
",year);
}
break;
case2:
printf("請輸入要判斷的日期:YearMonthDay>");
scanf("%d%d%d",&year,&month,&day);
totaldays=GetDays(year,month,day);
printf("%d年%d月%d日是%s
",year,month,day,WeekDay[(totaldays+1)%7]);
break;
case3:
printf("請輸入要顯示的月份:YearMonth>");
scanf("%d%d",&year,&month);
ShowCalendar(year,month,1);
break;
case4:
printf("請輸入要判斷的年份:Year>");
scanf("%d",&year);
for(month=1;month<=12;month++)
{
ShowCalendar(year,month,1);
}
break;
default:
printf("無效的菜單項!
");
break;
}
system("pause");
system("cls");
}
return0;
}