错误检查(Project将某年某月的日期表示方式转化为某年中第几天的表示方式)

#include <stdio.h>/*写法一*/
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	
	return 0;
}
static char dayab[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
int day_of_year(int year,int month,int day){
	int i;
	int leap;
	if(year<0){
		return -1;
	}
	else if(month<=0||month>12){
		return -1;
	}
	else{
	
	leap=year%4==0&&year%100!=0||year%400==0;
	
	for(i=0;i<month;i++){
		day+=dayab[leap][i];
	}
	return day;
	}
	
}
这个不够完善应该还要注意日子也要进行计算日子是不超过当月的最大天数。

以下是正确的程序:
#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	
	return 0;
}
static char dayab[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
int day_of_year(int year,int month,int day){
	int i;
	int leap;
	if(year<0)
		return -1;
	if(month<=0||month>12)
		return -1;
	if(day<1||day>dayab[leap][month])
		return -1;
	for(i=0;i<month;i++)
		day+=dayab[leap][i];
	return -1;
}

注意:1各个方面要考虑全面,日子,年,月……

2尽量写的简略比如if语句


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值