当前位置:首页 » 编程语言 » c语言打印月历
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言打印月历

发布时间: 2022-01-18 08:59:07

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
你看下吧