在DSP程序中建立C语言环境是有什么完成的
2个回答
展开全部
#include<stdio.h>
int isLeapYear(int year)
{
if( ( year%4==0 && year%100!=0) || (year%100==0) && ( year%3200!=0 ) )
return 1;
else return 0;
}
int main()
{
loop2:
int a[12]=;
int weekDay,c,y,temp;
int year,month,day;
char k;
printf("请按年月日格式输入(如1949 10 1): ");
loop: scanf("%d%d%d",&year,&month,&day);
//判断输入的年月日是否正确
if(year<0)
{
printf("年份不能为负数!请重输: ");
goto loop;
}
else if(month<1||month>12)
{
printf("输入月份只能在1-12之间!请重输: ");
goto loop;
}
else if(day<1||day>31)
{
printf("日的最大范围只在1-31之间!请重输: ");
goto loop;
}
else if(month==2 && day>29)
{
printf("二月没有%d日!请重输: ",day);
goto loop;
}
else if(month==2)
{
if(!isLeapYear(year) && day==29)
{
printf("该年不是闰年,二月没有29日!请重输: ");
goto loop;
}
}
else if(!a[month-1] && day==31)
{
printf("%d月是小月,没有31日!请重输: ",month);
goto loop;
}
//蔡勒(Zeller)公式:w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1
loop3: if( month==1 || month==2)
{
month+=12;
year--;
}
y = year % 100;
c = year / 100 ;
temp = y + y/4 + c/4 - 2*c + 26*(month+1)/10 + day - 1;
while(temp<0)
{
temp+=7;
}
weekDay = temp%7;
printf("\n\n那天正逢星期");
switch(weekDay)
{
case 0: printf("日");break;
case 1: printf("一");break;
case 2: printf("二");break;
case 3: printf("三");break;
case 4: printf("四");break;
case 5: printf("五");break;
case 6: printf("六");break;
}
printf("\n\n\n");
printf("退出程序吗?(y/n)\n\n");
do k=getchar();
while(k!='y'&&k!='n'&&k!='Y'&&k!='N');
if(k=='y'||k=='Y') ;
else goto loop2;
}
int isLeapYear(int year)
{
if( ( year%4==0 && year%100!=0) || (year%100==0) && ( year%3200!=0 ) )
return 1;
else return 0;
}
int main()
{
loop2:
int a[12]=;
int weekDay,c,y,temp;
int year,month,day;
char k;
printf("请按年月日格式输入(如1949 10 1): ");
loop: scanf("%d%d%d",&year,&month,&day);
//判断输入的年月日是否正确
if(year<0)
{
printf("年份不能为负数!请重输: ");
goto loop;
}
else if(month<1||month>12)
{
printf("输入月份只能在1-12之间!请重输: ");
goto loop;
}
else if(day<1||day>31)
{
printf("日的最大范围只在1-31之间!请重输: ");
goto loop;
}
else if(month==2 && day>29)
{
printf("二月没有%d日!请重输: ",day);
goto loop;
}
else if(month==2)
{
if(!isLeapYear(year) && day==29)
{
printf("该年不是闰年,二月没有29日!请重输: ");
goto loop;
}
}
else if(!a[month-1] && day==31)
{
printf("%d月是小月,没有31日!请重输: ",month);
goto loop;
}
//蔡勒(Zeller)公式:w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1
loop3: if( month==1 || month==2)
{
month+=12;
year--;
}
y = year % 100;
c = year / 100 ;
temp = y + y/4 + c/4 - 2*c + 26*(month+1)/10 + day - 1;
while(temp<0)
{
temp+=7;
}
weekDay = temp%7;
printf("\n\n那天正逢星期");
switch(weekDay)
{
case 0: printf("日");break;
case 1: printf("一");break;
case 2: printf("二");break;
case 3: printf("三");break;
case 4: printf("四");break;
case 5: printf("五");break;
case 6: printf("六");break;
}
printf("\n\n\n");
printf("退出程序吗?(y/n)\n\n");
do k=getchar();
while(k!='y'&&k!='n'&&k!='Y'&&k!='N');
if(k=='y'||k=='Y') ;
else goto loop2;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询