C语言打印日历问题求大佬
#include<stdio.h>intmain(void){inti,n,start_day;printf("Enternumberofdaysinmonth:");s...
#include <stdio.h>int main(void){ int i, n, start_day; printf("Enter number of days in month: "); scanf("%d", &n); printf("Enter starting day of the week (1=Sun, 7=Sat): "); scanf("%d", &start_day); printf("\n"); /* 打印空格 */ for (i = 1; i < start_day; i++) printf(" "); /* 打印日历 */ for (i = 1; i <= n; i++) { printf("%2d", i); if (((start_day + i - 1) % 7 != 0)&&(i!=n)) printf(" "); if ((start_day + i - 1) % 7 == 0) printf("\n"); } printf("\n"); return 0;}我的代码是这个。图一是题目,图二是OJ的结果。改了好多次,OJ突然变成这个样子看不懂了求大佬帮帮忙
展开
展开全部
程序好像没有问题啊:
#include <stdio.h>
int main(void)
{ int i, n, start_day;
printf("Enter number of days in month: ");
scanf("%d", &n);
printf("Enter starting day of the week (1=Sun, 7=Sat): ");
scanf("%d", &start_day);
printf("\n");
/* 打印空格 */
for (i = 1; i < start_day; i++)
printf(" ");
/* 打印日历 */
for (i = 1; i <= n; i++)
{ printf("%2d", i);
if (((start_day + i - 1) % 7 != 0)&&(i!=n))
printf(" ");
if ((start_day + i - 1) % 7 == 0)
printf("\n");
}
printf("\n");
return 0;
}
展开全部
#include <stdio.h>
void main()
{
int i,j,k,year,week;
int day[]={31,28,31,30,31,30,31,31,30,31,30,31};
char month[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"};
printf("Input year you want to print:");
scanf("%d",&year);
if((year%4==0&&year%100!=0)||(year%400==0)) day[1]++; //判断是否闰年
week=(35+year+year/4-year/100+year/400)%7; //计算当年的1月1日是周几的公式
for(i=0;i<12;i++)
{
printf("\n%s\n",month[i]); //输出月份的英文
printf("Sun Mon Tue Wed Thu Fri Sat\n"); //输出表头
for(k=0;k<week;k++) printf(" "); //每月一号对齐它的星期数
for(j=1;j<=day[i];j++)
{
printf("%3d ",j);
if(++week>=7)
{
printf("\n");
week=week%7;
}
}
printf("\n");
}
}
void main()
{
int i,j,k,year,week;
int day[]={31,28,31,30,31,30,31,31,30,31,30,31};
char month[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"};
printf("Input year you want to print:");
scanf("%d",&year);
if((year%4==0&&year%100!=0)||(year%400==0)) day[1]++; //判断是否闰年
week=(35+year+year/4-year/100+year/400)%7; //计算当年的1月1日是周几的公式
for(i=0;i<12;i++)
{
printf("\n%s\n",month[i]); //输出月份的英文
printf("Sun Mon Tue Wed Thu Fri Sat\n"); //输出表头
for(k=0;k<week;k++) printf(" "); //每月一号对齐它的星期数
for(j=1;j<=day[i];j++)
{
printf("%3d ",j);
if(++week>=7)
{
printf("\n");
week=week%7;
}
}
printf("\n");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用C++打印用一个自变量函数
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询