int main()
{
int i,j,a
scanf("%d",&a)
if(a==7)
{
a=0
}
else
{
a=a
}
printf("Sun Mon Tue Wed Thu Fri Sat\n")
for(i=1i<=ai++)
{
printf("%4c",' ')
}
for(j=1j<=30j++)
{
if((j+a)%7==0)
{
printf("%3d",j)
printf("\n")
}
else
printf("%3d ",j)
}
return 0//返回值
}
程序可以运行,就记得给main函数增加返回值,删去没有使用到的b和c就行了,其他正常
#include <conio.h>#include <stdio.h>
#include <time.h>
#include <stdlib.h>
const monthDay[] = {0,31,28,31,30,31,30,31,31,30,31,30,31}
int isLeap(int year)
{
if(year % 4) return 0
if(year % 400) return 1
if(year % 100) return 0
return 1
}
int getWeek(int year, int month, int day)
{
int c, y, week
if(month == 1 || month == 2) //判断month是否为1或2
{
year--
month+=12
}
c= year / 100
y = year - c * 100
week = (c / 4) - 2 * c + (y + y / 4) + (13 * (month + 1) / 5) + day - 1
while(week < 0) {week += 7}
week %= 7
return week
}
void display(int year, int month)
{
int monthDays, weekFirst, i
monthDays = monthDay[month] + (month==2 ? isLeap(year) : 0)
weekFirst = getWeek(year, month, 1)
system("cls")
printf(" -------%4d年----%2d月-------\n", year, month)
printf(" 星期日 星期一 星期二 星期三 星期四 星期五 星期六\n")
for(i=0 i<weekFirst i++) printf(" ")
for(i=1 i<=monthDays i++)
{
printf("%8d", i)
weekFirst++
if(weekFirst>=7) {printf("\n") weekFirst=0}
}
}
void main()
{
int year, month, chr
time_t timer
struct tm *tblock
timer = time(NULL)
tblock = localtime(&timer)
year = tblock->tm_year + 1900
month = tblock->tm_mon +1
while(1)
{
display(year, month)
chr = getch()
if(chr == 0xe0)
{
chr = getch()
if(chr == 0x4b) /* 方向键(←) */
{
month --
if(month<1) {month = 12 year--}
}
else if(chr == 0x4d) /* 方向键(→) */
{
month ++
if(month>12) {month = 1 year++}
}
}
else if(chr == 'q' || chr == 'Q') break
}
}
我这儿有一个万年历的程序,楼主可以试着编写实现你所需要的功能。希望有所帮助。#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=1i<monthi++)
dayCount+=n[i]
}
else
{
for(i=1i<monthi++)
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=0i<weekdayi++)
printf("\t")
if(IsLeap(year))
monthday=n[month]
else
monthday=m[month]
for(i=1i<=monthdayi++)
{
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=1i<=12i++)
{
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
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)