用指针的方式将某年某月转化为某年中的第几天

来源:互联网 发布:sql replace 单引号 编辑:程序博客网 时间:2024/05/17 04:38
第一种是自己写的不够完善
#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 *nonrunyear_month_day[]={"0","31","28","31","30","31","30","31","31","30","31","30","31"};static char *runyear_month_day[]={"0","31","29","31","30","31","30","31","31","30","31","30","31"};int day_of_year(int year,int month){int day;int leap;int i;leap=year%4==0&&year%100!=0||year%400==0;if(leap==0){for(i=0;i<month;i++){day+=*runyear_month_day[i];}}else{for(i=0;i<month;i++){day+=*nonrunyear_month_day[i];}}return day;}


0 0
原创粉丝点击