假设今天是某年某月某日求今天是今年的第几天
要注意的是闰年~! 不知道怎么做了哦
假设今天是某年某月某日求今天是今年的第几天
要注意的是闰年~! 不知道怎么做了哦
 2006-04-13 20:47
	    2006-04-13 20:47
   2006-04-13 20:52
	    2006-04-13 20:52
  
 2006-04-13 21:56
	    2006-04-13 21:56
  我是新手我也来试试:
#include "stdio.h"
main()
{
int i,flag,year,month,day,dayth; /*-----定义变量年/月/日/第几天----*/
 int month_day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};/*-----定义一维数组一个月有几天的取           值------*/  
 printf("\nplease input year /month/day:");
scanf("%d/%d/%d",&year,&month,&day); /*-----输入年/月/日-----*/
dayth=day;
flag=(year%400==0)||(year%4==0&&year%100!=0);/*---判断闰年----*/
if(flag)
month_day[2]=29; /*----是闰年,2月份改为29天----*/
for(i=1;i<month;i++) /*------使用for循环语句------*/
dayth=dayth+month_day[1]; /*---、日期累加----*/
printf("\n%d/%d/%d is %dth day",year,month,day,dayth);/*-----输出结果----*/
}
 编译环境为TC2.0。

 2006-04-16 10:57
	    2006-04-16 10:57
  #include<stdio.h>
struct datestruct
{
 int year;
 int month;
 int date;
};
void input(struct datestruct *);
void output(struct datestruct *datep);
int yunnian(int);
void main()
{
 struct datestruct date;
    input(&date);
 output(&date);
     
}
void input(struct datestruct *datep)
{
 printf("请按以下格式输入:\n");
 printf("year  month  date\n");
 scanf("%d %d %d",&(*datep).year,&(*datep).month,&(*datep).date );
}
void output(struct datestruct *datep)
{
 int i,date=0;
 int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
 for(i=1;i<(*datep).month;i++)
  date+=month[i-1];
    date+=(*datep).date;
 if(yunnian((*datep).year)&&(*datep).month>1)
  date++;
 printf("这一天是第%d天\n",date);
}
int yunnian(int year)
{
 if((year%4==0&&year%100!=0)||year%400==0)
  return 1;
 else return 0;
}
运行结果:
请按以下格式输入:
year  month  date
2006 2 12
这一天是第43天
 
 2006-04-16 11:27
	    2006-04-16 11:27
   2006-04-16 11:53
	    2006-04-16 11:53
   2006-04-16 12:16
	    2006-04-16 12:16
   2014-09-27 16:59
	    2014-09-27 16:59
   2014-09-27 17:02
	    2014-09-27 17:02