C语言编程练习(day of the year)
2010-11-28 01:38
302 查看
#include<stdio.h>
int sum_day(int month, int day); /*求得总天数,为考虑闰年*/
int leap(int year); /*是否闰年*/
int main(void)
{
int year, month, day;
int days;
printf("Please input the date(year,month,day): ");
scanf("%d,%d,%d", &year, &month, &day);
days = sum_day(month, day);
if(leap(year) && month >=3)
{
days = days + 1;
printf("This is leap year!\n");
}
else
{
printf("This is not leap year.\n");
}
printf("This is the %dth day of the year.\n", days);
return 0;
}
static int day_tab[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sum_day(int month, int day)
{
int i;
for(i=1; i<month; i++)
{
day = day + day_tab[i];
}
return day;
}
int leap(int year)
{
int lp;
lp = (year % 4 == 0 && year %100 != 0) || (year % 400 == 0);
return lp;
}
本文出自 “奋斗成就卓越” 博客,请务必保留此出处http://tiger506.blog.51cto.com/318536/434557
int sum_day(int month, int day); /*求得总天数,为考虑闰年*/
int leap(int year); /*是否闰年*/
int main(void)
{
int year, month, day;
int days;
printf("Please input the date(year,month,day): ");
scanf("%d,%d,%d", &year, &month, &day);
days = sum_day(month, day);
if(leap(year) && month >=3)
{
days = days + 1;
printf("This is leap year!\n");
}
else
{
printf("This is not leap year.\n");
}
printf("This is the %dth day of the year.\n", days);
return 0;
}
static int day_tab[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sum_day(int month, int day)
{
int i;
for(i=1; i<month; i++)
{
day = day + day_tab[i];
}
return day;
}
int leap(int year)
{
int lp;
lp = (year % 4 == 0 && year %100 != 0) || (year % 400 == 0);
return lp;
}
本文出自 “奋斗成就卓越” 博客,请务必保留此出处http://tiger506.blog.51cto.com/318536/434557
相关文章推荐
- matlab for循环应用(阶乘及the day of year)
- MonthOfTheYear、WeekOfTheYear、WeekOfTheMonth、DayOfTheYear ... 相对时间
- C语言 编程练习22题
- Windows下C语言的Socket编程练习
- Tip Of The Day : Be All That You Can Be铪铪
- C语言编程(练习1:分支和跳转 )
- LeetCode编程练习 - Intersection of Two Arrays II学习心得
- Recommand of the Day: 两个有趣的网站
- 2004.06.30,Wed - The Day of OS
- C语言编程(练习3:字符输入和输出 )
- 6/10/2009 Words of the Day
- PowerTip of the Day from powershell.com上周汇总(六)
- 程序设计入门——C语言 翁恺 第8周编程练习
- HDU 4028--The time of a day
- PowerTip of the Day-Removing Empty Things
- PowerTip of the Day-How Much RAM Do You Have?
- C语言的发展史(The Development of the C Language)
- PowerTip of the Day-Finding Invalid Aliases
- PowerTip of the Day-Getting Installed Updates
- C语言编程(练习2:数组和指针)