❶ c語言編寫程序「任意輸入一年份和月份,列印當月日歷。」
#include<stdio.h>
intisly(intyear)
{
return((!(year%4))&&(year%100)||(!(year%400)));
}
intmtod(intm)
{
intn=0;
switch(m)
{
case1:n=31;break;
case2:n=59;break;
case3:n=90;break;
case4:n=120;break;
case5:n=151;break;
case6:n=181;break;
case7:n=212;break;
case8:n=243;break;
case9:n=273;break;
case10:n=304;break;
case11:n=334;break;
default:n=0;
}
returnn;
}
intdmax(inty,intm)
{
if(m==2)
{
return28+(isly(y));
}
if((m==1||m==3||m==5||m==7||m==8||m==10||m==12))
return31;
return30;
}
intday(inty,intm)
{
intlyn=0;
intdn=0;
intweekday;
staticintaday[7]={2,3,4,5,6,0,1};
if(y>=1901)
{
for(inti=1901;i<=y;i++)
{
lyn+=isly(i);
}
if(isly(y))
{
if(m<=2)
lyn--;
}
dn=(y-1901)*365+mtod(m-1)+lyn;
weekday=aday[dn%7];
}
if(y<1901)
{
for(inti=y;i<1901;i++)
{
lyn+=isly(i);
}
if(isly(y))
{
if(m>2)
lyn--;
}
dn=(1901-y)*365-mtod(m-1)+lyn;
weekday=aday[dn%7];
}
returnweekday;
}
voidprintdate(inty,intm,intwd)
{
intcd=dmax(y,m);
intmdate[40]={0};
printf("日一二三四五六 ");
for(inti=0;i<cd;i++)
{
mdate[i+wd]=i+1;
}
for(inti=0;i<cd+wd;i++)
{
if(mdate[i]==0)
printf("");
else
printf("%3d",mdate[i]);
if((i+1)%7==0)
printf(" ");
}
printf(" ");
}
intmain()
{
inty,m;
printf("輸入年月:");
do
{
scanf("%d%d",&y,&m);
if(m<13&&m>0)
{
printf(" ");
printdate(y,m,day(y,m));
break;
}
else
printf("輸入不合法,請重新輸入:");
}
while(1);
return0;
}
❷ C語言 列印日歷
if(i==10)
這個去掉就可以了,不知道你這個要干什麼
❸ C語言中列印月歷
代碼沒標識有點難看,拿去運行了下,問題應該是出現在控制輸出上!
主要思想是
1、設置一個變數count
2、每輸出一天count++
3、若果count==當月的天數
4、則跳出輸出
這樣應該能解決多輸出幾天的問題了
❹ 用C語言編程,如何列印出當月的月歷(時間為計算機的當時時間)
大哥,你的分太少了,難怪沒人做,最少要80分,只有我這個人閑人練練手
好了,祝你看程序愉快!!!!
你看看是不是這個:
日歷---冰之龍製作
2010年9月
#include<stdio.h>
#include<time.h>
int*daysandweek(int*y,int*week);
boolrunnian(int*);
voidmain()
{
structtm*local;
time_tt;
t=time(0);
local=localtime(&t);
printf("日歷---冰之龍製作 ");
intyear,*y;
int*week,p=1;
week=&p;
intmonthday[]={31,28,31,30,31,30,31,31,30,31,30,31};
charmonth[12][12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
charweekday[7][4]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
year=local->tm_year;year+=1900;
printf("%d年%d月 ",year,local->tm_mon+1);
printf(" ");
y=&year;
if(runnian(y))
monthday[1]=29;
daysandweek(y,week);
for(intj=0;j<=11;j++)
{if(j==local->tm_mon){
for(intk=0;k<15;k++)
printf("");printf("%s ",month[j]);
printf("_____________________________________ ");
for(intg=0;g<=6;g++)
printf("%s",weekday[g]);
printf(" ");
for(intx=1;x<=*week;x++)
for(k=0;k<5;k++)
printf("");
for(intm=1;m<=monthday[j];m++)
{
if((*week+m)%7==0)
printf("%d ",m);
else
if(m<10)
printf("%d",m);
else
printf("%d",m);
}
printf(" ");
}
*week=(*week+monthday[j])%7;
}
}
boolrunnian(int*y)
{
int*t=y;
if(*t%4==0&&*t%100!=0||*t%100==0&&*t%400==0)
returntrue;
else
returnfalse;
}
int*daysandweek(int*y,int*week)
{
intdays=1,*z;
for(inti=1;i<*y;i++)
{
z=&i;
days+=365;
if(runnian(z))
days++;
}
*week=days%7;
returnweek;
}
❺ 求C語言「列印日歷」程序!!!!!
#include <stdio.h>
void main()
{
int i,j,k,year,week;
int day[]={31,28,31,30,31,30,31,31,30,31,30,31};
char month[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"};
printf("Input year you want to print:");
scanf("%d",&year);
if((year%4==0&&year%100!=0)||(year%400==0)) day[1]++; //判斷是否閏年
week=(35+year+year/4-year/100+year/400)%7; //計算當年的1月1日是周幾的公式
for(i=0;i<12;i++)
{
printf("\n%s\n",month[i]); //輸出月份的英文
printf("Sun Mon Tue Wed Thu Fri Sat\n"); //輸出表頭
for(k=0;k<week;k++) printf(" "); //每月一號對齊它的星期數
for(j=1;j<=day[i];j++)
{
printf("%3d ",j);
if(++week>=7)
{
printf("\n");
week=week%7;
}
}
printf("\n");
}
}
❻ 用C語言編寫程序列印任意年份的日歷
#include <stdio.h>
int JgYr(int yr)
{
if (yr%4==0&&yr%100!=0||yr%100==0&&yr%400==0)
return 1;
else
return 0;
}
int CalWkd(int yr,int mth)
{
int ds=0,i,rst,wkd;
int mthd[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if (JgYr(yr))
mthd[2]=29;
for (i=1;i<mth;i++)
ds+=mthd[i];
ds+=1;
rst=yr-1+(int)((yr-1)/4)-(int)((yr-1)/100)+(int)((yr-1)/400)+ds;
wkd=rst%7;
return wkd;
}
showcld(int wkd,int mtd)
{
int dt=1,i,j=0;
printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");
for (i=0;i<wkd;i++)
{
printf("\t");
j++;
}
while (j!=7)
{
printf("%d",dt);
if (j<6)
printf("\t");
else
printf("\n");
dt++;
j++;
}
while (1)
{
for (j=0;j<7;j++)
{
printf("%d",dt);
if (j!=6)
printf("\t");
else
printf("\n");
if (dt!=mtd)
dt++;
else
return 0;
}
}
}
int main()
{
int yr,mth,mtd,wkd,mthd[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("Input the Year and Month(Year-Month):");
scanf("%d-%d",&yr,&mth);
if (yr<0||mth<1||mth>12)
return 0;
if (JgYr(yr))
mthd[2]=29;
mtd=mthd[mth];
wkd=CalWkd(yr,mth);
showcld(wkd,mtd);
return 0;
}
❼ 用c語言編程:列印年歷
沒想到這個程序會做這么長,要不得多要點分。
#include <stdio.h>
void main()
{
int i,j,k,year,week;
int day[]={31,28,31,30,31,30,31,31,30,31,30,31};
char month[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"};
printf("Input year you want to print:");
scanf("%d",&year);
if((year%4==0&&year%100!=0)||(year%400==0)) day[1]++;
week=(35+year+year/4-year/100+year/400)%7; //計算當年的1月1日是周幾的公式
for(i=0;i<12;i++)
{
printf("\n%s\n",month[i]);
printf("Sun Mon Tue Wed Thu Fri Sat\n");
for(k=0;k<week;k++) printf(" ");
for(j=1;j<=day[i];j++)
{
printf("%3d ",j);
if(++week>=7)
{
printf("\n");
week=week%7;
}
}
printf("\n");
}
}
❽ c語言 輸出月歷
voidcalender(intinput)
{
inti;
printf("SunMonTueWenThuFriSat ");
for(i=1;i<30+input;i++)
{
if(i<input){
printf("");
}
else{
printf("%3d",i-input+1);
}
if(0==i%7){
printf(" ");
}
elseif(30!=i-input+1){
printf("");
}
}
}
❾ c語言列印月歷 怎麼編寫啊~ 謝謝!
我這兒有一個萬年歷的程序,樓主可以試著編寫實現你所需要的功能。希望有所幫助。
#include<stdio.h>
#include<stdlib.h>
int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int n[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
char w[7][3]={"日","一","二","三","四","五","六"};
char mon[13][7]={"","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
/*判斷是否為閏年*/
int IsLeap(int year)
{
if((year%4==0 && year%100!=0)||(year%400==0))
return 1;
else
return 0;
}
/*計算某年某月某日是星期幾*/
int Getweekday(int year,int month,int day)
{
int weekday;
int dayCount=0;
int i;
if(IsLeap(year))
{
for(i=1;i<month;i++)
dayCount+=n[i];
}
else
{
for(i=1;i<month;i++)
dayCount+=m[i];
}
dayCount=dayCount+day;
weekday=((year-1)+(year-1)/4-(year-1)/100+(year-1)/400+dayCount)%7;
return weekday;
}
/*判斷某年某月某日是星期幾的函數*/
void SelectDay()
{
int year,month,day;
char ch;
int weekday;
printf("請輸入年月日(xxxx-xx-xx):\t");
scanf("%d-%d-%d",&year,&month,&day);
weekday=Getweekday(year,month,day);
printf("\n");
printf("%d年%d月%d日是:星期%s\n",year,month,day,w[weekday]);
printf("\n您還需要繼續查詢嗎?\t是(Y)/否(N)");
getchar();
ch=getchar();
if(ch=='y'||ch=='Y')
SelectDay();
}
/*輸出某月的日歷*/
void GetMonth(int year,int month )
{
int weekday,i,monthday;
weekday=Getweekday(year,month,1);
printf("日\t一\t二\t三\t四\t五\t六\n");
for(i=0;i<weekday;i++)
printf("\t");
if(IsLeap(year))
monthday=n[month];
else
monthday=m[month];
for(i=1;i<=monthday;i++)
{
printf("%2d\t",i);
weekday++;
if(weekday%7==0)
printf("\n");
}
printf("\n");
}
/*列印某年某月日歷函數*/
void Month()
{
int year,month;
char ch;
printf("請輸入年月(xxxx-xx):\t");
scanf("%d-%d",&year,&month);
printf("\n");
GetMonth(year,month );
printf("\n您還需要繼續查詢嗎?\t是(Y)/否(N)");
getchar();
ch=getchar();
if(ch=='y'||ch=='Y')
Month();
}
/*列印某年日歷函數*/
void Year()
{
int year,i;
char ch;
printf("請輸入年份:\n");
scanf("%d",&year);
for(i=1;i<=12;i++)
{
printf("%s\n",mon[i]);
GetMonth(year,i);
printf("\n\n");
}
printf("\n您還需要繼續查詢嗎?\t是(Y)/否(N)");
getchar();
ch=getchar();
if(ch=='y'||ch=='Y')
Year();
}
/*退出程序*/
void Exit()
{
char ch;
getchar();
printf("是否確定退出?\t是(Y)/否(N)");
ch=getchar();
if(ch=='y'||ch=='Y')
printf("感謝您的使用!!\n\n");
exit(0);
}
/*主函數*/
void main()
{
int choice;
while(1)
{
printf("歡迎使用該系統!!\n");
printf("**===**===**===**===**===**===**===**===**===**\n");
printf("1.查詢某年某月某日是星期幾\n");
printf("2.列印某年某月的全月日歷\n");
printf("3.列印某年的全年日歷\n");
printf("4.退出系統\n");
printf("**===**===**===**===**===**===**===**===**===**\n");
printf("請輸入您需要進行的操作前面的序號: ");
scanf("%d",&choice);
switch(choice)
{
case 1:SelectDay(); break;
case 2:Month(); break;
case 3:Year(); break;
case 4:Exit(); break;
}
}
}
❿ c語言編程:列印年歷
基於你對問題的描述c語言編程:列印年歷
可以跟我詳細交流下
ES://DL5858DLls
你看下吧