程序好像没有问题啊:
#include
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
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
{
printf("%3d ",j);
if(++week>=7)
{
printf("\n");
week=week%7;
}
}
printf("\n");
}
}
用C++打印用一个自变量函数