满意答案
hbhb5210
2013.12.20
采纳率:44% 等级:13
已帮助:19747人
scanf("%c",c);这个变量c干嘛不给地址呢?!还有,这个程序写得。。。说实话,比较乱,提示说明文字也是在乱用,不看代码直接运行的话,完全叫人看不懂。好几年没有写c程序了,过会儿给你试着改的工整点。。。还有,不要一直用while(1)这种结构和break;没必要的。
#include
void print_days(int days_before, int num_days)
{
int y;
printf("****************************************************\n");
printf("SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\n");
y = days_before % 7;
switch(y)
{
case 1:printf("\t");break;
case 2:printf("\t\t");break;
case 3:printf("\t\t\t");break;
case 4:printf("\t\t\t\t");break;
case 5:printf("\t\t\t\t\t");break;
case 6:printf("\t\t\t\t\t\t");break;
default:break;
}
for(int i = 1; i <= num_days; i++)
{
printf("%d\t",i);
if( (i + y) % 7 == 0)
printf("\n");
}
printf("\n");
}
void main()
{
int t, h, day;
char c;
do
{
do
{
printf("Enter month in 2013 to display calendar (1-12):\n");
scanf("%d", &t);
} while (t <= 0 || t > 12);
switch (t)
{
case 1:h=2;day=31;break;
case 2:h=31;day=28;break;
case 3:h=31+28;day=31;break;
case 4:h=31+28+31;day=30;break;
case 5:h=31+28+31+30;day=31;break;
case 6:h=31+28+31+30+31;day=30;break;
case 7:h=31+28+31+30+31+30;day=31;break;
case 8:h=31+28+31+30+31+30+31;day=31;break;
case 9:h=31+28+31+30+31+30+31+31;day=30;break;
case 10:h=31+28+31+30+31+30+31+31+30;day=31;break;
case 11:h=31+28+31+30+31+30+31+31+30+31;day=30;break;
case 12:h=31+28+31+30+31+30+31+31+30+31+30;day=31;break;
default:break;
}
print_days(h, day);
gets(&c);
printf("Would you like to display another month (y/n) ?");
scanf("%c",&c);
} while (c =='y' || c=='Y');
}
00分享举报