gpt4 book ai didi

c - 使用 C 为日历控制台应用程序添加选项卡

转载 作者:行者123 更新时间:2023-11-30 17:50:34 26 4
gpt4 key购买 nike

我正在使用 ANSI C 在控制台应用程序中以传统格式实现一个简单的年度日历。该日历必须选项卡才能以 3 x 4 个月的格式显示。到目前为止,我设法将所有月份显示在彼此下方,如下面的代码所示。有什么帮助我如何解决选项卡部分吗?我尝试根据列将月份[]分成3部分,例如一月、四月、七月和十月将是第一列,然后逐列工作,但我不知道这是否是最好的做法。 ..有什么帮助吗?

#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);
}

最佳答案

可以替换

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

...

关于c - 使用 C 为日历控制台应用程序添加选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17187753/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com