我正在使用ANSI C在控制台应用程序中实现一个简单的传统格式的年历。该日历必须加标签才能以3 x 4个月的格式显示。到目前为止,我成功地显示了所有月份,如下面的代码所示。有什么帮助吗?我该如何处理标签部分呢?我试着把month[]按列分成3列,例如1月、4月、7月和10月将是第1列,然后逐列工作,但我不知道这是不是最好的do...any帮助吗?
#include<stdio.h>
int main()
{
int d,y,no_lp,n,i=1,j,month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("Enter year:");
scanf("%d", &y);
if (y%4==0)
{month[2]=29;}
no_lp= (27 + (42/5) + (y-1) + ((y-1)/4) - ((y-1)/100) + ((y-1)/400) + 1);
d= no_lp%7;
n=d;
for(j=1;j<=12;j++)
{
printf("\n\n %s",monthname[j]);
//printf ("\n\n%d",j);
printf("\n Su Mo Tu We Th Fr Sa\n");
while(d--!=0)
printf(" "); //spaces for empty days
while(i<=month[j])
{
if(i<10)
{printf(" %d ",i++);} //formating for dates with 2 digits
else{printf("%d ",i++);}//formatting for dates with 1 digit
n++;
if(n==7) //if 7 is reached start new line
{
n=0;
printf("\n");
}
}
d=n;
i=1; //n will be the 1st day of next month
}
return(0);
}发布于 2013-06-19 18:48:02
你可以替换
if(i<10)
{printf(" %d ",i++);} //formating for dates with 2 digits
else{printf("%d ",i++);}//formatting for dates with 1 digit使用
printf("%2d ",i++);为了打印3* 4,不要在飞行中打印
存储这些值
char out[12][6][24];
| | |
n months <- | -> string containing week in calendar (e.g 10 11 12 13 14 15 17)
V
Max weeks in a month和打印
week 1 month 1 , week 1 month 2 , week 1 month 3
week 2 month 1 , week 2 month 2 , week 2 month 3
week 3 month 1 , week 3 month 2 , week 3 month 3
...
week 1 month 4 , week 1 month 5 , week 1 month 6
week 2 month 4 , week 2 month 5 , week 2 month 6
week 3 month 4 , week 3 month 5 , week 3 month 6
...
...https://stackoverflow.com/questions/17187753
复制相似问题