判断你的出生是否为闰年,是否到达投票年龄和法定饮酒年龄
代码如下:
#define CURRENTYEAR 2013
#include<stdio.h>
int birth_year, age;
int main() {
printf(“Enter the you were born: “);
scanf(”%d”, &birth_year);
//判断用户是否在闰年出生
if (birth_year % 4 == 0)
printf("You were born in a leap year!\n");
else
printf("You were not born in a leap year!\n");
age = CURRENTYEAR - birth_year;
//判断用户是否到达投票年龄和法定饮酒年龄
if (age >= 18)
printf("You can vote this year!\n ");
if (age <= 21)
printf("It is illegal for you to drink alcohol!\n");
return 0;
}
运行结果如下:
更多资源加群聊。