#include <stdlib.h>
void print_jige(int a[4])
{
if(a[0]>=60&&a[1]>=60&&a[2]>=60&&a[3]>=60)
{
printf("平均成绩是:\t%lf\n",(a[0]+a[1]+a[2]+a[3])*1./4)
}
}
int main()
{
int a[20]
int i
int j=0
int a1[4] int a2[4] int a3[4] int a4[4] int a5[4]
printf("请输入第%d名同学的四门成绩:\t",1)
for(i=0i<=19i++)
{
if((i+1)%4==0&&i!=19)
{
printf("请输入第%d名同学的四门成绩:\t",(i+1)/4+1)
}
if(i<=3&&i>=0) scanf("%d",&a1[i])
if(i>=4&&i<=7) scanf("%d",&a2[i-4])
if(i<=11&&i>=8) scanf("%d",&a3[i-8])
if(i>=12&&i<=15) scanf("%d",&a4[i-12])
if(i<=19&&i>=16) scanf("%d",&a5[i-16])
}
print_jige(a1)
print_jige(a2)
print_jige(a3)
print_jige(a4)
print_jige(a5)
return 0
}
#include<iostream.h>#include<iomanip.h>
#include<conio.h>
int HowManyDays(int year ,int month)
int DayOfWeek(int year )
void show()
int main()
{
int year
cout<<"请输入年份:"<<endl
cin>>year
static int j1=1
static int j2=1
static int j3=1
int weekday=DayOfWeek(year)
for(int i=0i<4i++)
{
show()
int n = 0
int k = 0
int m = 0
while(1)
{
while(1)
{
int _month=3*i+1
int Days=HowManyDays(year, _month)
for( j1 = n+1j1<weekday+Days+1j1++)
{
if(weekday==0)
cout<<setw(3)<<j1
else{
if(j1<weekday+1)
cout<<setw(3)<<" "
else
cout<<setw(3)<<j1-weekday
}
n++
if(n%7 == 0)
break
}
break
}
while(1)
{
int _month=3*i+2
int Days=HowManyDays(year,_month)
for( j2 = k+1j2<weekday+Days+1j2++)
{
if(weekday==0)
cout<<setw(3)<<j2
else{
if(j2<weekday+1)
cout<<setw(3)<<" "
else
cout<<setw(3)<<j2-weekday
}
k++
if(k%7==0)
break
}
break
}
while(1)
{
int _month=3*i+3
int Days=HowManyDays(year,_month)
for( j3 = m+1j3<weekday+Days+1j3++)
{
if(weekday==0)
cout<<setw(3)<<j3
else{
if(j3<weekday+1)
cout<<setw(3)<<" "
else
cout<<setw(3)<<j3-weekday
}
m++
if(m%7==0)
{
cout<<endl
break
}
}
break
}
int _month=3*i+3
int Days=HowManyDays(year,_month)
if(j3>=weekday+Days+1)
break
}
}
getch()
return 0
}
int HowManyDays(int year ,int month) //计算一个月有多少天
{
int days
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
return days=31
else if(month==2){
if(year%4==0&&year%100!=0||year%400==0)
return days=29
else return days=28
}
else
returndays=30
}
int DayOfWeek(int year ) //判断星期几
{
int i
int _month[12]
for(i = 0i <12i++)
_month[i]=HowManyDays(year,i)
int weekday=0
weekday = (year-1+(year-1-1)/4)%7
return weekday
}
void show()
{
for(int j=1j<=3j++)
{
static int month=1
cout<<setw(8)<<" "<<month<<" 月"<<setw(15)<<" "
if(j%3==0)
cout<<endl
month++
}
for(int k=1k<=3k++)
{
cout<<"-----------------------"<<setw(5)<<" "
if(k%3==0)
{
cout<<endl
}
}
for(int l=1l<=3l++)
{
cout<<setw(1)<<"日 "<<setw(1)<<" 一 "<<setw(1)<<"二 "<<setw(1)<<" 三 "
cout<<setw(1)<<" 四 "<<setw(1)<<" 五 "<<setw(1)<<"六 "
cout<<setw(2)<<" "
if(l%3==0)
{
cout<<endl
}
}
for(int m=1m<=3m++)
{
cout<<"-----------------------"<<setw(5)<<" "
if(m%3==0)
{
cout<<endl
}
}
}
基本功能已经实现:
/*****************************************************************
*Author :wacs5
*DATE :20101110(YYYMMDD)
*Email :wacs5@126.com
*Function :用C编写、打印万年历
*Targe :http://zhidao.baidu.com/question/195084859.html
*Compiler :TC2.0、Gcc通过(如果是VC++的话,去掉#include <conio.h>)
* *另外getch()函数可以换成system("pause")语句.
*****************************************************************/
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
int DaysInMonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}
int DaysInYear[13]={0,31,59,90,120,151,181,212,243,273,304,334,365}
char MonthInfo[13][4]={"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}
char WeekInfoEng[8][4]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}
char WeekInfoChs[8][3]={"天","一","二","三","四","五","六"}
int main()
{
int year,month,day
int flag=1 /*是否输出到文件,1为输出,0为不输出*/
long date1
int IsLoopYear(int year)
int CheckDay(int year,int month,int day)
long Date2Long(int year,int month,int day)
int Week(long day)
int PrintNow(int flag)
int MonthCalendar(int year,int month,int flag)
int YearCalendar(int year,int flag)
int PrintNumMask(int year,char ch,FILE *fp)
PrintNow(flag) /*输出当月月历并输出时间,flag=1代表输出到文件*/
printf("year=")
scanf("%d",&year)
YearCalendar(year,flag) /*输出2010年年历,flag=1代表输出到文件*/
getch()
}
/*判断闰年*/
int IsLoopYear(int year)
{
return year%400==0 || (year%100 && year%4==0)
}
/*检查日期的合法性*/
int CheckDay(int year,int month,int day)
{
int IsLoopYear(int year)
/*年月日大于零,月份为1-12,日期为1至当月最大的天数,注意二月份的闰月*/
if (year>=0 && month>0 && month<=12 && day>0 && \
day<=( DaysInMonth[month]+(month==2&&IsLoopYear(year)) ) )
return 1
else
return 0
}
/*返回year年month月day日到0000年1月0日(抽象的时间)的天数*/
long Date2Long(int year,int month,int day)
{
long days
days=year*365l+year/4-year/100+year/400 + (year>0) /*year年1月0日经历的天数,0年是闰年*/
days+=DaysInYear[month-1]+ (month>2&&IsLoopYear(year)) + day /*加上月份以及天数*/
return days
}
/*计算星期*/
int Week(long days)
{
return (days+5)%7
}
/*输出现在时刻,并输出当月日历*/
int PrintNow(int flag)
{
time_t now
struct tm *tm_1
int Week(long day)
int CheckDay(int year,int month,int day)
long Date2Long(int year,int month,int day)
int MonthCalendar(int year,int month,int flag)
time(&now)
tm_1=localtime(&now)
MonthCalendar(tm_1->tm_year+1900,tm_1->tm_mon+1,flag)
printf("今天是:%4d年%02d月%02d日,星期%s\n",tm_1->tm_year+1900,tm_1->tm_mon+1,tm_1->tm_mday,WeekInfoChs[tm_1->tm_wday])
printf("当前时间是:%02d时%02d分%02d秒\n",tm_1->tm_hour,tm_1->tm_min,tm_1->tm_sec)
return 1
}
/*输出月历*/
int MonthCalendar(int year,int month,int flag) /*flag=1时,写文件*/
{
int i,k,day,week
long days
char filename[80]
int Week(long day)
int CheckDay(int year,int month,int day)
long Date2Long(int year,int month,int day)
FILE *fp
if (flag)
{
sprintf(filename,"%04d_%02d.txt",year,month)
fp=fopen(filename,"w")
if (fp==NULL)
{
printf("File Open Error in Function:MonthCalendar\nPress any key to exit:")
getch()
exit(-1)
}
}
day=1
if (!CheckDay(year,month,day))
{
printf("Format:%d-%d-1(YYYY-MM-DD) is invaild in Function:MonthCalendar\n",year,month)
return 0
}
days=Date2Long(year,month,day)
week=Week(days)
k=(4*7-9)/2
for (i=0i<ki++)
filename[i]=' '
filename[k]='\0'
printf("MonthCalendar:\n%s%d--%s\n",filename,year,MonthInfo[month])
if (flag)
fprintf(fp,"%s%d--%s\n",filename,year,MonthInfo[month])
for (i=0i<7i++)
{
printf("%s ",WeekInfoEng[i])
if (flag)
fprintf(fp,"%s ",WeekInfoEng[i])
}
printf("\n")
if (flag)
fprintf(fp,"\n")
for (i=0i<weeki++)
{
printf(" ")
if (flag)
fprintf(fp," ")
}
for (i=dayi<=DaysInMonth[month]+(month==2)*(IsLoopYear(year))i++) /*闰年的2月份,要加一*/
{
printf("%3d ",i)
if (flag)
fprintf(fp,"%3d ",i)
if ((i+week)%7==0)
{
printf("\n")
if (flag)
fprintf(fp,"\n")
}
}
printf("\n")
if (flag)
{
fprintf(fp,"\n")
fclose(fp)
}
return 1
}
/*输出年历*/
int YearCalendar(int year,int flag)
{
int month_col=2 /*每行几个月历*/
int space_col=4 /*两个月历的空格数*/
int month_row=(int)ceil(12.0/month_col)
int line,end_day[13],keepgoing[13]={1}
int i,j,k,month,day[13],week[13]
long days[13]
char space[3][80]
int Week(long day)
int CheckDay(int year,int month,int day)
long Date2Long(int year,int month,int day)
int PrintNumMask(int year,char ch,FILE *fp)
FILE *fp
if (flag)
{
char filename[80]
sprintf(filename,"%04d.txt",year)
fp=fopen(filename,"w")
if (fp==NULL)
{
printf("File Open Error in Function:YearCalendar\nPress any key to exit:")
getch()
exit(-1)
}
}
for (month=1month<=12month++)
{
day[month]=1
if (!CheckDay(year,month,day[month]))
{
printf("Format:%d-%d-1(YYYY-MM-DD) is invaild in Function:YearCalendar\n",year,month)
return 0
}
days[month]=Date2Long(year,month,day[month])
week[month]=Week(days[month])
keepgoing[month]=1
}
k=(7*4-3)/2
for (i=0i<ki++) /*月份标识前空格*/
space[0][i]=' '
space[0][i]='\0'
for (i=0i<7*4-3-ki++) /*月份标识后空格*/
space[1][i]=' '
space[1][i]='\0'
for (i=0i<space_coli++) /*两列之间的空格*/
space[2][i]=' '
space[2][i]='\0'
PrintNumMask(year,'*',stdout)
PrintNumMask(year,'*',fp)
month=1
for (i=0i<month_rowi++)
{
for (j=0j<month_colj++) /*输出月份的缩写*/
{
printf("%s%s%s",space[0],MonthInfo[month+j],space[1]) /*前导空格,月份缩写,后导空格*/
if (flag)
fprintf(fp,"%s%s%s",space[0],MonthInfo[month+j],space[1])
if (j<month_col-1) /*月份列与列之间的空格*/
{
printf("%s",space[2])
if (flag)
fprintf(fp,"%s",space[2])
}
}
printf("\n") /*换行*/
if (flag)
fprintf(fp,"\n")
for (j=0j<month_colj++)
{
for (k=0k<7k++) /*星期的缩写*/
{
printf("%s ",WeekInfoEng[k])
if (flag)
fprintf(fp,"%s ",WeekInfoEng[k])
}
if (j<month_col-1) /*月份列与列之间的空格*/
{
printf("%s",space[2])
if (flag)
fprintf(fp,"%s",space[2])
}
}
printf("\n") /*换行*/
if (flag)
fprintf(fp,"\n")
for (j=0j<month_colj++) /*横线*/
{
for (k=0k<7k++) /*横线*/
{
printf("____",WeekInfoEng[k])
if (flag)
fprintf(fp,"____",WeekInfoEng[k])
}
if (j<month_col-1) /*月份列与列之间的空格*/
{
printf("%s",space[2])
if (flag)
fprintf(fp,"%s",space[2])
}
}
printf("\n") /*换行*/
if (flag)
fprintf(fp,"\n")
for (j=0j<month_colj++)/*第一行*/
{
for (k=0k<week[month+j]k++) /*1号之前的放空*/
{
printf(" ")
if (flag)
fprintf(fp," ")
}
for (k=1k<=7k++)
{
printf("%3d ",k)
if (flag)
fprintf(fp,"%3d ",k)
if ((k+week[month+j])%7==0)
{
end_day[month+j]=k+1
printf("%s",space[2])
if (flag)
fprintf(fp,"%s",space[2])
break
}
}
}
printf("\n") /*换行*/
if (flag)
fprintf(fp,"\n")
for (line=0line<5line++)
{
for (j=0j<month_colj++)
{
if (keepgoing[month+j]==0) /*补一行空格行*/
for (k=0k<7k++)
{
printf(" ")
if (flag)
fprintf(fp," ")
}
else
{
for (k=end_day[month+j]k<=DaysInMonth[month+j]+(month==2)*(IsLoopYear(year))k++)
{
printf("%3d ",k)
if (flag)
fprintf(fp,"%3d ",k)
if ((k+week[month+j])%7==0)
{
end_day[month+j]=k+1
break
}
}
if (k>=DaysInMonth[month+j]+(month==2)*(IsLoopYear(year)))
keepgoing[month+j]=0
if (k>DaysInMonth[month+j]+(month==2)*(IsLoopYear(year))) /*补空格*/
{
for (k<100k++)
{
printf(" ")
if (flag)
fprintf(fp," ")
if ((k+week[month+j])%7==0)
break
}
}
}
if (j<month_col-1) /*月份列与列之间的空格*/
{
printf("%s",space[2])
if (flag)
fprintf(fp,"%s",space[2])
}
}
printf("\n") /*换行*/
if (flag)
fprintf(fp,"\n")
/*每行中各个月份是否都已经输出完毕*/
k=0
for (j=0j<month_colj++)
k+=keepgoing[month+j]
if (k==0)
break
}
month += month_col
printf("\n") /*换行*/
if (flag)
fprintf(fp,"\n")
}
if (flag)
fclose(fp)
return 1
}
/*数字模输出*/
int PrintNumMask(int year,char ch,FILE *fp)
{
/*5*5数字模*/
int mask[10][5]={ {31,17,17,17,31},{ 1, 1, 1, 1, 1},\
{31,1 ,31,16,31},{31, 1,31, 1,31},\
{17,17,31, 1, 1},{31,16,31, 1,31},\
{31,16,31,17,31},{31, 1, 1, 1, 1},\
{31,17,31,17,31},{31,17,31, 1,31}}
int digit[16]={0}
char space=' '
int i,j,k,n
n=0
while(year)
{
digit[n++]=year%10
year/=10
}
for (i=0i<5i++) /*行*/
{
for (k=0k<nk++) /*字的第i行*/
{
for (j=0j<5j++) /*列*/
{
if ( mask[digit[n-1-k]][i] & (1<<(4-j)) )
fprintf(fp,"%c",ch)
else
fprintf(fp,"%c",space)
}
fprintf(fp,"%c",space)
}
fprintf(fp,"\n")
}
return 1
}
输出结果:
当月月历以及2010年年历
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)