用c语言计算高考成绩,C语言计算距离高考剩余时间
每年6月6日定為高考,輸入日期:xxxx.xx.xx,若沒到6月6日,則算距離今年的,否則算明年的。
#include
#define uint unsigned int
/*月份天數,1月31,2月28/29,3月31,4月30,5月31,6月30,7月31,8月31,9月30,10月31,11月30,12月31*/
/*判斷是否是閏年*/
uint is_ruennian(uint x)
{
if(x%4==0)
{
if(x%100==0)
{
if(x%400==0)
return(1);//是閏年
else
return (0);//不是閏年
}
else
return (1);//是閏年
}
return (0);
}
/*ACII轉成int*/
uint asciitoint(char *p,uint n)
{
uint i,temp=0;
for(i=0;i
{
temp*=10;
temp+=*p-48;
}
return (temp);
}
/*計算距離6月6日的天數*/
uint caculate_days(uint year,uint month,uint day)
{
uint temp=0;
if(month<6)
{
ca1:
temp+=6-day;
switch (6-month)
{
case 1:
case 2:
case 5:
temp+=(6-month)*30+1;
break;
case 3:
temp+=(6-month)*31;
break;
case 4:
temp+=(6-month)*30;
break;
}
if((6-month>3)&&(is_ruennian(year)==1))
temp+=1;
}
else if(month==6)
{
if(day<=6)
goto ca1;
else
goto ca2;
}
else
{
ca2:
temp+=day-6;
switch (month-6)
{
case 1:
temp+=(month-6)*30+1;
break;
case 2:
case 3:
temp+=(month-6)*30+2;
break;
case 4:
case 5:
temp+=(month-6)*30+3;
break;
case 6:
temp+=(month-6)*30+4;
break;
}
if(is_ruennian(year+1)==1)
temp=366-temp;
else
temp=365-temp;
}
return (temp);
}
void main()
{
uint year,month,day;
char flag=1,time[10];//存放日期
printf("****************這是一個計算距離高考還有多少天的工具****************\n");
printf("******************輸入日期的格式為:xxxx.xx.xx**********************\n");
while(flag)
{
printf("請輸入當前日期,并按下回車鍵結束:");
gets((char *)time);
year=asciitoint((char *)time,4);
month=asciitoint((char *)(time+5),2);
day=asciitoint((char*)(time+8),2);
printf("當前日期%d年%d月%d日,",year,month,day);
printf("距離高考還有%d天\n",caculate_days(year,month,day));
printf("結束請輸入0并按回車,繼續請輸入1并按回車:");
if(getchar()=='0')
flag=0;
else if(getchar()=='1')
flag=1;
}
}
總結
以上是生活随笔為你收集整理的用c语言计算高考成绩,C语言计算距离高考剩余时间的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 热门!!Squid缓存加速——传统及透明
- 下一篇: 2.5 zio入门——ZIO类型别名