C language: Determining whether a year is a leap year and the problem of chicken and rabbit in the same cage

#include<stdio.h>
int main()
{   
    int year;    
	printf("请输入年份:\n");
	scanf("%d",&year);
	if((year%4==0)&&(year%100!=0)||(year%100==0)&&(year%400==0)){
		printf("%d是闰年",year); 
	}
	else{
		printf("%d不是闰年",year);
	}
	return 0;
} 


"&&" is the AND operation; "||" is the OR operation;

The following is a problem of chickens and rabbits in the same cage: input the total number of chickens and rabbits as m, and the total number of legs as n, calculate and output the number of chickens and rabbits.

#include<stdio.h> 
int main() 
{ 
int m,n,x,y; 
printf("请输入鸡、兔子的头以及脚的的个数和都应为偶数\n"); 
scanf("%d %d",&m,&n); 
if((4*m-n>0)&&(n-2*m>0)) 
{ 
x=(4*m-n)/2;  
y=(n-2*m)/2; 
printf("鸡的个数为%d,子的个数为为%d\n",x,y); 
} 
else 
printf("不存在这样的组合\n");
return 0;
}
It can be assumed that x and y are the numbers of chickens and rabbits respectively, and it can be deduced that x=(4*mn)/2 and y=(n-2*m)/2.


Guess you like

Origin blog.csdn.net/samxiaoguai/article/details/78535643
Recommended