那不能直接用哈`~`
除非定义为全局变量..
还可以作为函数参数``~
若还要改变它的值呢~`就用指针参数咯..
还是直接看程序吧有问题:
#include<stdio.h>
int date=0;
void week()/*判断这一天是星期几*/
{switch(date%7)
case0: printf("That Day Is SUNDAY");break;
case1: printf("That Day Is MONDAY");break;
case2: printf("That Day IS TUESDAY");break;
case3: printf("That Day Is WENSDAY");break;
case4: printf("That Day Is THURSDAY");break;
case5: printf("That Day Is FIRDAY");break;
case6: printf("That Day Is SATURDAY");break;
}
main()
{
int b,i,k,year,leap,month,day;
int monthday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
clrscr();
clrscr();printf("Please Input a Year:") ;
scanf("%d",&year);
if(year%4==0)/*判断闰年*/
{ if(year%100==0)
{ if(year%400==0)
leap=1;
else leap=0;
}
else leap=1;
}
else leap=0;
cl-rscr();
printf("Please Input a Month:") ;
scanf("%d",&month);
while(1)
{
if(month>12||month<=0)
{
printf("Input Error!Please Input a Month Again:") ;
scanf("%d",&month);
}
else{
clrscr();
break;
}
}
printf("Please Input a Day:");
scanf("%d",&day);
for(i=0;i<month-1;i++)
{ date=monthday[i]+date ;
}
if(leap==1) date++;
date=date+day;
clrscr();/*输出这一天是这一年的第几天*/
printf("%d,%d,%d Is The %d Day Of The Year",year,month,day,date);
week();
return 0;
}
少加了{},浪费我时间
#include<stdio.h>
int date=0;
void week()/*判断这一天是星期几*/
{
{switch(date%7)
case0: printf("That Day Is SUNDAY");break;
case1: printf("That Day Is MONDAY");break;
case2: printf("That Day IS TUESDAY");break;
case3: printf("That Day Is WENSDAY");break;
case4: printf("That Day Is THURSDAY");break;
case5: printf("That Day Is FIRDAY");break;
case6: printf("That Day Is SATURDAY");break;
}
}
不过你即使判断出是闰年又怎么样,建议你写一个二维数组
main()
{
int b,i,k,year,leap,month,day;
int monthday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
clrscr();
clrscr();printf("Please Input a Year:") ;
scanf("%d",&year);
if(year%4==0)/*判断闰年*/
{ if(year%100==0)
{ if(year%400==0)
leap=1;
else leap=0;
}
else leap=1;
}
else leap=0;
cl-rscr();
printf("Please Input a Month:") ;
scanf("%d",&month);
while(1)
{
if(month>12||month<=0)
{
printf("Input Error!Please Input a Month Again:") ;
scanf("%d",&month);
}
else{
clrscr();
break;
}
}
printf("Please Input a Day:");
scanf("%d",&day);
for(i=0;i<month-1;i++)
{ date=monthday[i]+date ;
}
if(leap==1) date++;
date=date+day;
clrscr();/*输出这一天是这一年的第几天*/
printf("%d,%d,%d Is The %d Day Of The Year",year,month,day,date);
week();
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int date=0;
void week()/*判断这一天是星期几*/
{
switch(date%7)
{
case 0: printf("That Day Is SUNDAY");break; //中间要用一个空格隔开
case 1: printf("That Day Is MONDAY");break;
case 2: printf("That Day IS TUESDAY");break;
case 3: printf("That Day Is WENSDAY");break;
case 4: printf("That Day Is THURSDAY");break;
case 5: printf("That Day Is FIRDAY");break;
case 6: printf("That Day Is SATURDAY");break;
}
}
main()
{
int b,i,k,year,leap,month,day;
int monthday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
printf("Please Input a Year:") ;
scanf("%d",&year);
if(year%4==0)/*判断闰年*/
{
if(year%100==0)
{
if(year%400==0)
leap=1;
else
leap=0;
}
else
leap=1;
}
else leap=0;
printf("Please Input a Month:") ;
scanf("%d",&month);
while(1)
{
if(month>12||month<=0)
{
printf("Input Error!Please Input a Month Again:") ;
scanf("%d",&month);
}
else
{
break;
}
}
printf("Please Input a Day:");
scanf("%d",&day);
for(i=0;i<month-1;i++)
{
date=monthday[i]+date ;
}
if(leap==1)
date++;
date=date+day;
/*输出这一天是这一年的第几天*/
printf("%d,%d,%d Is The %d Day Of The Year",year,month,day,date);
week();
return 0;
}