当前位置:首页 » 编程语言 » c语言输出日历

c语言输出日历

发布时间: 2022-07-29 04:01:30

c语言程序编写日历

/*你好,这个问题我来回答,希望能被采纳:*//*函数功能输出year的日历*/#include<stdio.h>void
main(){int
a,b,c,d,e,f,i,j,k,n,m,year;printf("input
the
year:\n");
scanf("%d",&year);
//输入数据的初始化;b=year;c=year%4;d=year/4;e=d*1461+c*365;f=e%7;j=f;
//初始化Year年的第一天的星期;m=j;printf("***%d年的日历***\n",year);for(a=1;a<=12;a++)
//函数的主要部分,主要实现日历的打印部分
{
if(a==1||a==3||a==5||a==7||a==8||a==10||a==12)k=31;
else
if(a==4||a==6||a==9||a==11)k=30;
else
if((year%4==0&&year%100!=0)||(year%400==0))k=29;
else
k=28;
printf("%d月份\n
STAT
SUN
MON
TUE
WED
THUR
FRI\n",a);
m=j;
if(m<=5)m=m+1;
else
m=m-6;
for(n=1;n<=m;n++)printf("
");
for(i=1;i<=k;i++,j++)
{if(j==7)j=0;
if(i<10)printf("
%d",i);
else
printf("
%d",i);
if(j==5)printf("\n");
}
printf("\n\n\n");
}}

❷ 用c语言编写万年历,要求输出任意一年的某月,能显示出这个月的日历

1、首先要判断一个年份是闰年还是平年,用一个子程序来做。

❸ C语言编写日历

#include <stdio.h>
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
void print_calendar(int y);
void main()
{
int y;
printf("Calendar system :\n");
printf("Please input a year between 1600 & 2500:");
while(scanf("%d",&y)!=EOF)//输入年份
{
if (y<1600 || y>2500)
{
printf("Invalid input. Please try again!\n");
printf("Please input a year between 1600 & 2500:");
continue;
}
print_calendar(y);
}
}

void print_calendar(int y) //打印日历
{
int i,sum,days,k,m;
char monthname[12][20] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
if((0==y%4&&y%100!=0)||0==y%400 ) //闰年判断
month[2]=29;

for(m=1;m<13;m++)
{
days = 0;
for (i=1;i<m;i++) //计算m月1号是第几天
days+=month[i];
days++;
sum=y-1+(y-1)/4-(y-1)/100+(y-1)/400+days;
k=sum%7; //k是星期几,k=0星期日
printf("%s %d\n",monthname[m-1],y);
printf(" S M Tu W Th F S\n");
printf("%*d",3*(k+1)-1,1);//先输出3*(k+1)-1个空格,在输出1
k++;
for(i=2;i<=month[m];i++)
{
if(k == 7)
{
printf("\n");
k=0;
}
if (k == 0)
printf("%2d",i);
else
printf("%3d",i);
k++;
}
printf("\n\n");
}
}

❹ C语言编写万年历~~速度

/*C语言编程万年历
要求输入年月,判断是否闰年;
输入年月日,判断星期几;
输入年份,打出12个月的月历;
输入年份,月份,打印出本月日历;
要求用多个函数实现。*/
#include<stdio.h>
#include<time.h>
#include<string.h>int calendar[12][6][7];/*月历*/
char* week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Satarday"};
char* Monthname[]={"January","February","March","April","May","June","July",
"August","September","October","November","December"};
int monthday[]={31,28,31,30,31,30,31,31,30,31,30,31};
char* menu[]={/*操作菜单*/
"1.Input a year number,check whether it's a leap year.\n",
"2.Input year,month,day,check the weekday.\n",
"3.Input year,month,output the calendar of that month.\n",
"4.Input year,output all the month calendar.\n",
"0.Exit.\n"
};/*判断参数year传递的年份是否是闰年*/
int IsLeapyear(int year)
{
if(!(year%4)&&year%100||!(year%400)) return 1;
else return 0;
}/*输入年月日,判断星期几,利用Zeller公式w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1
w是结果星期数,y是年份的后两位,c是年份的前两位,m是月份,3≤m≤14,也就是当
m≤2时,要算到前一年的13月份和14月份,最后要将w对7取模
*/
int WeekDay(int year,int month,int day)
{
int w,y,c,m,d;
c=year/100;
if(month<3){
m=12+month;
y=year%100-1;
}
else{
m=month;
y=year%100;
}
d=day;
w=y+y/4+c/4-2*c+26*(m+1)/10+d-1;
return (w%7+7)%7;
}/*输入年份,月份,打印出本月的日历*/
void Monthly(int year,int month)
{
int weekday,i,j;
if(month==2)
if(IsLeapyear(year)) monthday[1]+=1;
weekday=WeekDay(year,month,1);
printf("%s\n",Monthname[month-1]);
printf("Sun. Mon. Tue. Wed. Thu. Fri. Sat.\n");
for(i=1,j=weekday;i<=monthday[month-1];i++,j++){
calendar[month-1][j/7][j%7]=i;
}
for(i=0;i<6;i++){
for(j=0;j<7;j++)
{
if(calendar[month-1][i][j]==0) printf("%5c",' ');
else printf("%-5d",calendar[month-1][i][j]);
}
printf("\n");
}
}void allMonth(int year) /*输入年份,打印出12个月的月历*/
{
int i;
for(i=1;i<=12;i++){
Monthly(year,i);
getch();/*按任意键继续执行*/
}
}void main(void)
{
int year,month,day,i,n,weekday;
memset(&calendar,sizeof(calendar),0); /*初始化月历*/
for(i=0;i<5;i++)
printf("%s",menu[i]);
while(1){
printf("Please choose the menu:");
scanf("%d",&n);
printf("\n");
switch(n){
case 1:
printf("Please input year:");
scanf("%d",&year);
if(IsLeapyear(year)) printf("\n%d is leap year.\n",year);
else printf("%d isn't leap year.\n",year);
break;
case 2:
printf("Please input year month day:");
scanf("%d%d%d",&year,&month,&day);
printf("\n");
weekday=WeekDay(year,month,day);
printf("That day is %s\n",week[weekday]);
break;
case 3:
printf("Please input year month,then it output a calendar of that month:");
scanf("%d%d",&year,&month);
printf("\n");
Monthly(year,month);
break;
case 4:
printf("Please input year,then it will output the calendar of that year:");
scanf("%d",&year);
printf("\n");
allMonth(year);
break;
case 0:
return;
default:
printf("The number you input is invalid.\n");
break;
}
}
getch(); /*按任意键,程序退出*/
}这个程序是可用的~~希望能帮到你~~~

❺ 利用c语言输出某月日历

#include <stdio.h>
#include <string.h>

bool isLeapYear(int);
int getWeekDay(int, int, int);

int main(int argc, char const *argv[])
{
int year;
int month;

printf("输入日期(yyyy-mm):");
scanf("%d-%d-%d", &year, &month);//输入年和月

printf(" %d年%d月\n", year, month);//输出日历日历标题
printf("日 一 二 三 四 五 六\n");//输出星期

//本函数获取某个日期是星期几,这里获取每月的1号是星期几,返回是是[0-7]对应(星期天-星期六)
int week = getWeekDay(year, month, 1);

int i;
for (i = 0; i < week; i++)//每月第一周前几天用空格填充
printf(" ");

int endDayOfMonth;//每个月的最后一天
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
endDayOfMonth = 31;
else if (month == 2)
{
if (isLeapYear(year))
endDayOfMonth = 29;
else
endDayOfMonth = 28;
}
else
endDayOfMonth = 30;

int dayOfMonth = 1;
//从一号循环到本月末
while (dayOfMonth <= endDayOfMonth)
{
printf("%2d ", dayOfMonth);
dayOfMonth++;
//每输出完星期六的日期后就换行(对应周数起点是从week开始的,所以要在天数上加上week)
if ((dayOfMonth + week- 1) % 7 == 0)
printf("\n");
}
printf("\n");
return 0;
}

//判断闰年
bool isLeapYear(int y)
{
if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
return true;
return false;
}

//获取某天是星期几返回值(0-7)
int getWeekDay(int y, int m, int d)
{
//计算星期几的固定公式,Y是年D是这个日期在本年的天数
//W = [Y-1] + [(Y-1)/4] - [(Y-1)/100] + [(Y-1)/400] + D
int days = d;
int i;
for (i = 1; i < m; i++)
{
if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)
days += 31;
else if (i == 2)
{
if (isLeapYear(y))
days += 29;
else
days += 28;
}
else
days += 30;
}

int temp = y - 1 + (int)((y - 1) / 4) - (int)((y - 1) / 100) + (int)((y - 1) / 400) + days;
return temp % 7;
}

❻ 如何用c语言做个日历表

1、功能要求

1)输入任一年将显示出该年的所有月份日期,对应的星期
2)注意闰年情况
其显示格式要求如下:
1)份:中文英文都可以,
2)下一行显示星期,从周日到周六,中英文都可以
3)下一行开始显示日期从1号开始,并按其是周几实际情况与上面的星期数垂直对齐
2、例程:
#include <stdio.h>
#include<conio.h>
#include<stdlib.h>
int IsLeapYear(int); //声明头文件和函数
void 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}; //每个月的天数,最后一个是闰年2月
printf("Please enter the year: ");
scanf("%d",&year); //输入年份
while(Year_Start < year) //计算从公元1年1月1日到你所查询年份前一年的天数,是为了以后确定这一年的第一天是星期几
{
if( IsLeapYear( Year_Start ) ) //确定一年的天数,闰年为366天,一般为365天
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); //如 January(2008)
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) //闰年的2月
while( day <= month_day[12] )
{
if( day >1 )
if( Year_days % 7 == 0 ) //如果不是1号且昨天是星期天,输入回车, 换行
printf("\n");
if( day >= 10 ) //如果大于或等于10号则输出日期并加2个空格,小于10号输出日期并加3个空格
printf("%d ",day); //开始没想到这几行是干嘛用的,只要一个输出就好嘛,后来才想到是用来调整格式的

else //只是他并没有调整好,我做了下修改,现在很整齐了
printf("%d ",day);
Year_days++;
day++;
}
else //不是闰年2月的
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' ) //输入q退出程序
exit(0);
}
getch();
}
int IsLeapYear( int year ) //判断是否为闰年
{
if ((year %4 == 0) && (year % 100 != 0) || //年份能被4整除且不能被100整除 或者 能被400整除的为闰年
(year % 400 == 0) )
return 1;
else
return 0;
}

❼ C语言日历输出求教

#include <stdio.h>
#include <windows.h>

int main()
{
int y,m=1,d,p,n,t,w,k=0,i=1;
printf("欢迎使用查询日历输出程序.\n");
printf("请输入查询年份: ");
scanf("%d",&y);
switch(y%4 == 0)
{
case 1:
{
int a[13]={0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int c[12]={0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
t = y - 1;
p = (t / 4) - ((t / 400) * 3);
for(m=1;m<=12;m++)
{
n = (p * 366 + (t - p) * 365 + 1 + c[m-1]) % 7;
w = n + 1;
printf("\n\n %d月\n 一 二 三 四 五 六 日\n",m);
d = 1;
for(k = 1; k <= n; k++) printf(" ");
for(;k<=7;k++) printf("%4d", d++);
for(i=1;i<40;i++)
{
if(i%7 ==1) printf("\n");
printf("%4d", d++);
if(d > a[m]) break;
}
}
break;
}
default:
{
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int c[12]={0,31,59,90,120,151,181,212,243,273,304,334};
t = y - 1;
p = (t / 4) - ((t / 400) * 3);
for(m=1;m<=12;m++)
{
n = (p * 366 + (t - p) * 365 + 1 + c[m-1]) % 7;
w = n + 1;
printf("\n\n %d月\n 一 二 三 四 五 六 日\n",m);
d = 1;
for(k = 1; k <= n; k++) printf(" ");
for(;k<=7;k++) printf("%4d", d++);
for(i=1;i<40;i++)
{
if(i%7 ==1) printf("\n");
printf("%4d", d++);
if(d > a[m]) break;
}
}
break;
}

}
printf("\n");
system("PAUSE");
return 0;
}

热点内容
ios6G与安卓12G哪个更快 发布:2025-01-24 11:26:22 浏览:827
下线源码 发布:2025-01-24 11:26:22 浏览:523
windows8解压软件 发布:2025-01-24 11:04:41 浏览:559
蓝牙聊天源码 发布:2025-01-24 11:03:13 浏览:124
安卓是什么意思是vivo吗 发布:2025-01-24 11:01:32 浏览:486
悬赏网源码 发布:2025-01-24 10:53:14 浏览:733
c语言时间变量 发布:2025-01-24 10:40:24 浏览:869
ppiandroid 发布:2025-01-24 10:25:50 浏览:1001
儿童压缩机 发布:2025-01-24 10:25:09 浏览:75
苹果的允许访问在哪里 发布:2025-01-24 10:24:32 浏览:32