if-else语句
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
void main()
{
int year;//声明变量
printf("\n输入年份:");
scanf("%d", &year);//赋空间
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) //闰年:4年一闰 百年不闰 四百年又闰
{
printf("\n%d 是闰年", year);
}
else//上面结果为假就执行下面这个
{
printf("\n%d 不是闰年", year);
}
return(0);//结束
}
if-else-if语句
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include<stdlib.h>
void main()
{
float a = 0;
printf("\n输入一个数字:");
scanf("%f", &a);
if (a > 0)
{
printf("plus\n");
}
else if (a<0)
{
printf("negative\n");
}
else
{
printf("zero\n");
}
system("pause");
}