主题:小白有难,大大们帮帮忙。。。。谢了
/*一个判断闰年的简单程序但有点没想通,本人标准的小白大大门别笑*/
#include"stdio.h"
main()
{
int year,leap;
scanf("%d",&year);
if(year%4==0)
{
if(year%100==0)
{
if(year%400==0)
leap=1;
else
leap=0;
}
else
leap=1;
}
else
leap=0;
if(leap) /*这是什么意思啊?在C里面定义一个参数(这里是leap)为1就默认为是真吗?就可以作为判读依据吗?*/
printf("%d is ",year);
else
printf("%d is not ",year);
printf("a leap year.\n");
}
还有如果我这样编:
#include"stdio.h"
main()
{
int year , leap;
scanf("%d",&year);
if( year%4==0&&year%100!=0||year%100==0&&year%400==0 )/*if( (year%4==0&&year%100!=0)||(year%100==0&&year%400==0 )这句加上括号和没加,应该是一样的吧?他们的优先级决定的。。。。不一样请解释下。。谢了 )*/
leap=1;
else
leap=0;
if(leap)
printf("%d is a",year);
else
printf("%d is not a ");
printf("leap year");
}
#include"stdio.h"
main()
{
int year,leap;
scanf("%d",&year);
if(year%4==0)
{
if(year%100==0)
{
if(year%400==0)
leap=1;
else
leap=0;
}
else
leap=1;
}
else
leap=0;
if(leap) /*这是什么意思啊?在C里面定义一个参数(这里是leap)为1就默认为是真吗?就可以作为判读依据吗?*/
printf("%d is ",year);
else
printf("%d is not ",year);
printf("a leap year.\n");
}
还有如果我这样编:
#include"stdio.h"
main()
{
int year , leap;
scanf("%d",&year);
if( year%4==0&&year%100!=0||year%100==0&&year%400==0 )/*if( (year%4==0&&year%100!=0)||(year%100==0&&year%400==0 )这句加上括号和没加,应该是一样的吧?他们的优先级决定的。。。。不一样请解释下。。谢了 )*/
leap=1;
else
leap=0;
if(leap)
printf("%d is a",year);
else
printf("%d is not a ");
printf("leap year");
}