c语言编写万年历请求高手帮忙当输入年份时日期是对的可同时输入了月份时就不对了

作者&投稿:岑受 (若有异议请与网页底部的电邮联系)
求C语言高手帮忙 编写一个程序 输入年份后就可以查询该年每个月的日历(公历) 急求啊 20分~

#include
#include

int IsLeapYear(int year)
{
if((year%4==0&&year%100!=0)||(year%400==0))
return 1;
else
return 0;
}

int month_day(int year,int month)
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(IsLeapYear(year)&&month==2)
return 29;
else
return(mon_day[month-1]);
}

int DaySearch(int year,int month,int day)
{
int c=0;
float s;
int m;
for(m=1;m<month;m++)
c=c+month_day(year,m);
c=c+day;
s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;
return ((int)s%7);
}

int PrintAllYear(int year)
{
int temp;
int i,j;
printf("

%d year
",year);
for(i=1;i<=12;i++)
{
temp=DaySearch(year,i,1);
if(i==1)
{
if(temp==0) printf("
first day is %d
",7);
else printf("
first day is %d
",temp);
}
printf("

%d month
",i);
printf(" S M T W T F S
");
for(j=1;j<=month_day(year,i)+temp;j++)
{
if(j-temp<=0)
printf(" ");
else
printf("%3d",j-temp);

if(j%7==0)
printf("
");
}
}
return 0;
}

void main()
{
int year;

printf("
Please input a year(XXXX)");
scanf("%d",&year);
PrintAllYear(year);
}

日历这东西最好先知道一年的第一天是周几这里有个公式(year+(year-1)/4-(year-1)/100+(year-1)/400)%7运行结果图示
我写了一个代码用DevC++4.9.9.2编译通过在VC++6.0下也可以正常编译代码如下#include #include #include #include using namespace std; //By Shilyx oversleep@163.com char *monthname[]={"","January","February","March","April","May","June","July","August","September","October","November","December"};char *weekname[]={"","Mon","Tue","Wed","Thu","Fri","Sat","Sun"};int monthday[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; void pr_week();int GetFirstDayOfMonth(int year,int month);void pr_month(int weekday,int month); int main(int argc, char *argv[]){ int year,month; system("color f0"); if(argc>3) { cout system("pause>nul"); exit(0); } if(argc>1) { year=atoi(argv[1]); if(argc>2) month=atoi(argv[2]); else month=0; if(year30000 || month12) { cout system("pause>nul"); exit(0); } } else { cout cin >>year; cout cin >>month; while(year30000 || month12) { cout cin >>year>>month; } } if(month!=0) { cout pr_month(GetFirstDayOfMonth(year,month),month); } else { system("cls"); //输出全年时进行清屏 cout for(int i=1;i { cout pr_month(GetFirstDayOfMonth(year,i),i); } } system("PAUSE>nul"); return EXIT_SUCCESS;} void pr_week(){ for(int i=1;i cout cout } int GetFirstDayOfMonth(int year,int month){ int firstdayofyear; int firstdayofmonth=0; if((year%4==0 && year%100!=0) || year%400==0) monthday[2]=29; else monthday[2]=28; firstdayofyear=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7; for(int i=1;i firstdayofmonth+=monthday[i]; firstdayofmonth=(firstdayofmonth+firstdayofyear)%7; if(firstdayofmonth==0) firstdayofmonth=7; //得0是不对的 return firstdayofmonth;} void pr_month(int weekday,int month){ int i,j; cout pr_week(); //cout for(i=1;i cout for(j=1;j { cout if(i%7==0 && j!=monthday[month]) cout } cout }

#include"stdio.h"
#define YES 1
#define NO 0
int isleap(int year)
{
int leap=NO;
if(year%4==0 && year%100!=0 || year%400==0)
leap = YES;
return leap;
}
int week_of_firstday(int year)
{
int n;
n=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7;

return n;
}
int main()
{
int year,month,day,weekday,len_of_month,i;
printf("请输入年份:");
scanf("%d",&year);
weekday=week_of_firstday(year);
for(month=1;month<=12;month++)
{
printf("\n"); printf(" %d年%d月\n",year,month);
printf("---------------------\n");
printf("日 一 二 三 四 五 六\n");
printf("---------------------\n");
for(i=0;i<weekday;i=i+1)
printf(" ");
if(month==4||month==6||month==9||month==11)
len_of_month=30;
else if(month==2)
{
if(isleap(year))
len_of_month=29;
else
len_of_month=28;
}
else
len_of_month=31;

for(day=1;day<=len_of_month;day++)
{
if(day>9)
printf("%d ",day);
else
printf("%d ",day);
weekday++;
if(weekday==7)
{
weekday=0;
printf("\n");
}
}
printf("\n");

}
return 0;
}

不是每年的二月都是28天


用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 ...

C语言万年历
C语言万年历 20 1、输入一个年份,在屏幕上输出该年的年历(包括每月的天数和所对应的星期几),并且在每月的左上角或右上角打印出相应的年份和月份,要求输出界面尽可能整齐、美观,符合年历显示规范... 1、输入一个年份,在屏幕上输出该年的年历(包括每月的天数和所对应的星期几),并且在每月的左上角或右上角...

用C语言编万年历
include <stdio.h> include<conio.h> include<stdlib.h> int IsLeapYear(int);int 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};printf(...

万年历(C语言编程)
include<stdio.h> include 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;...

哪位高手能给一个用C语言写的万年历
\/\/ Yuna_2006_10_16 \/\/ A program of a celinder include <iostream> using std::cin;using std::cout;using std::endl;\/\/ the use of setw include <iomanip> using std::setw;define BEGINYEAR 2000 \/\/ the year i use to begin define BEGINDAY 6 \/\/ 2000`s first day const...

求助:用C语言编万年历程序
include "stdio.h"int week(int y,int m,int d);void main(){ int monthday[12]={31,28,31,30,31,30,31,31,30,31,30,31};int y,w,i,m=1,d=1;printf("请输入一个年份yyyy:\\n");scanf("%d",&y);if (y%4==0&&y%100!=0) monthday[1]=29;for(m=1;m<=12;m++)...

用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 ...

用C语言编写万年历系统
万年历#include"stdio.h"\/*RequiredforMS-DOSuse*\/#defineENTER0x1C0D\/*Enterkey*\/intyear,month,day;staticchar*days[8]={"","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};structTIMEDATE{intyear;\/*year1980..2099*\/intmonth;\/*month1=Jan2=Feb,etc.*\/intday;\/*day...

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) ...

c语言中编写万年历的代码要用到那些函数?
include"stdio.h"define YES 1 define NO 0 int isleap(int year){ int leap=NO;if(year%4==0 && year%100!=0 || year%400==0)leap = YES;return leap;} int week_of_firstday(int year){ int n;n=(year+(year-1)\/4-(year-1)\/100+(year-1)\/400)%7;return n;} int ...

临桂县18922058872: c语言编写万年历请求高手帮忙当输入年份时日期是对的可同时输入了月份时就不对了 -
卜冰欣美: #include"stdio.h"#define YES 1#define NO 0 int isleap(int year) { int leap=NO; if(year%4==0 && year%100!=0 || year%400==0) leap = YES; return leap; } int week_of_firstday(int year) { int n; n=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7; ...

临桂县18922058872: 求用C语言编写一个万年历,要求输入年月,输出相应月份的日历~ -
卜冰欣美: // aa.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<stdio.h> #include<stdlib.h> #include<time.h> #include<windows.h> #include<conio.h> #include<math.h> void tiangan(int x) {char a[][10]={"甲","乙","丙","...

临桂县18922058872: 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...

临桂县18922058872: 用c语言设计一个简单的万年历怎么写代码 -
卜冰欣美: #include"stdio.h"#include"stdlib.h"main(){intYear,Month;//年、月intFirstDay_Year,FirstDay_Month;//某年的第一天是星期几,某年某月的第一天是星期几(范围是0~6,其中0代表星期日)intIsLeapYear;//是否为闰年,0表示不是闰年,...

临桂县18922058872: 求c语言编写万年历,要求输入一个年份,会显示那一个年份的一到十二月,还包括星期几.会的大神求解 -
卜冰欣美: 我写过一个程序,输入日期能显示出是星期几,我把代码给你,你先给我采纳,我下午四点帮你写,现在没时间.//输入日期 能知道是星期几.#include<stdio.h> int run(int n,int y,int r);//润平年判断与计算函数,结果为,此日期为当年的第几天...

临桂县18922058872: 急求c语言制作的万年历
卜冰欣美: #include "stdio.h" void main() { int year,month,day,sum=0,h=0,i,week; char answer; printf("*********************欢迎使用万年历**********************\n");do { fflush(stdin); printf("请输入年份:"); scanf("%d",&year); printf("请输入月份...

临桂县18922058872: 跪求C语言编写的万年历 -
卜冰欣美: 我自己写的,不过时输入年份显示该年的年历,比月历要稍微难一点,稍微改一下就行了,你看看.我们当时用的环境是DEVC++,是通过的. #include<stdio.h> int monthDay(int,int); int IsLeapYear(int); main() {int days,weekDay,year,month=1,...

临桂县18922058872: 求一个万年历C语言编程 急用啊 -
卜冰欣美: #include<stdio.h>#include<time.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==...

临桂县18922058872: 怎么用c语言编写万年历,要求输入日期显示星期 -
卜冰欣美: //算元旦的星期 s=x-1+(x-1)/4-(x-1)/100+(x-1)/400+c x为年 c为从元旦起的总天数#include "iostream.h"#include "stdlib.h" void print1(int y) { cout<<y<<"月"<<"\t\t"<<"日"<<"\t"<<"一"<<"\t"<<"二"<<"\t"<<"三"<<"\t"<<"...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网