帮忙解释几个程序

来源:百度知道 编辑:UC知道 时间:2024/05/21 07:56:34
程序L5_11.C功能:输入年、月、日,输出该日期是该年的第几天
---------------------------------------------------------*/
#include <stdio.h>

/*函数is_leap_year()判断年year是否是闰年,如果是返回值为1,否则为0*/
int is_leap_year(int year)
{ int leap;
if (year%4==0&&year%100!=0||year%400==0) leap=1;
else leap=0;
return leap;}

/*函数len_of_month()的返回值为某年year的某月month的天数*/
int len_of_month(int year,int month)
{ int month_days;
if (month==2)
if (is_leap_year(year)) month_days=29;
else month_days=28;
else if (month==4||month==6||month==9||month==11) month_days=30;
else month_days=31;
return month_days;}

/*函数len_of_days()的返回值为该日期date是该年year的第几天*/
int len_of_days(int year,int month,int date)
{ int total_days,n;
for(n=1,total_days=0;n<month;n++)
total_days+=len_of_month(year,n);
total_days+=date;
return total_days;}

void main

程序L5_11.C:
if (year%4==0&&year%100!=0||year%400==0) leap=1;
//闰年的计算规则:年份是4的倍数并且不是100的倍数或者是400的倍数

if (month==2)
if (is_leap_year(year)) month_days=29; //闰年的2月是28天
else month_days=28; //否则是28天
else if (month==4||month==6||month==9||month==11) month_days=30; //4,6,9,11是30天
else month_days=31; //其它月份是31天

for(n=1,total_days=0;n<month;n++)
total_days+=len_of_month(year,n); //计算前几月的天数
total_days+=date; //加上本月已经过去的天数
//得到某月某日是今天的第几天

程序L5_9.C功能:求三个数的最大数:
max=a>(b>c?b:c)?a:(b>c?b:c);
//如果a大于b,c中较大的,则最大小以,否则为b,c中较大的数

程序L5_7.C功能:自增运算符和自减运算符的演示示例:
关于++运算和--运算:如果运算符在变量之前(如++a),则是先将变量的值加1(或减1),再返回表达式的值,既为加1后的值,在后面的话是先将值返回再加1

程序L5_5.C功能:阅读程序,写出结果并演算:
int a=5,b=4,c=3;
if (a>b&&a>c) s=a; //运算的优先顺序为:
(a>b)&&(a>c)
(a>b)=(5>4)=1
a>c=5>3=1
1&&1=1==>条件为真s=a=5

else s=0;
t=!(a-c>1||2&&0);
(a-c