/*
Name: C语言经典算法100例004
Copyright: *
Author: 巧若拙
Date: 25-08-14 07:08
Description:
题目:输入某年某月某日,判断这一天是这一年的第几天?
(year能被4整除 and 不能被100整除) or year能被400整除
*/
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<math.h>
void fun1(void);
int LeapYear(int year);
int main(void)
{
fun1();
system("pause");
return 0;
}
int LeapYear(int year)//判断是否为闰年
{
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
return 1;
else
return 0;
}
void fun1(void)
{
int MonthLib[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int year, month, day;
int i, count = 0;
puts("请输入日期(年月日用空格隔开):");
scanf("%d %d %d", &year, &month, &day);
if (LeapYear(year)) //如果是闰年,2月为29天
MonthLib[1] = 29;
count = day;
for (i=0; i<month-1; i++)
count += MonthLib[i];
printf("\n这天是该年的第 %d 天\n", count);
}
Name: C语言经典算法100例004
Copyright: *
Author: 巧若拙
Date: 25-08-14 07:08
Description:
题目:输入某年某月某日,判断这一天是这一年的第几天?
(year能被4整除 and 不能被100整除) or year能被400整除
*/
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<math.h>
void fun1(void);
int LeapYear(int year);
int main(void)
{
fun1();
system("pause");
return 0;
}
int LeapYear(int year)//判断是否为闰年
{
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
return 1;
else
return 0;
}
void fun1(void)
{
int MonthLib[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int year, month, day;
int i, count = 0;
puts("请输入日期(年月日用空格隔开):");
scanf("%d %d %d", &year, &month, &day);
if (LeapYear(year)) //如果是闰年,2月为29天
MonthLib[1] = 29;
count = day;
for (i=0; i<month-1; i++)
count += MonthLib[i];
printf("\n这天是该年的第 %d 天\n", count);
}