1.4 Chicken and rabbit cage
The total number of chickens and rabbits is known to be n and the total number of legs is m. Enter N and m, output the number of chickens and the number of rabbits in turn.
#include <stdio.h>intMain () {//Chicken and rabbit cage problem intA, B, M, N; scanf ("%d%d", &m, &n);//m total number of legs, n total numberA = (4*N-M)/2; b= N-A; if(M%2==1|| A <0|| b <0) printf ("No answer!"); Elseprintf ("%d%d\n", A, b); return 0;}View Code
The logical operators in the C language are short-circuit operators. Once the value of the entire expression can be determined, the calculation is no longer continued.
1.5 Ordering of three integers
//three-integer sort 2017-6-29#include <stdio.h>intMain () {intA, B, C, t; scanf ("%d%d%d", &a, &b, &c); if(A > B) {T = A; a = b; b =T;} if(A > C) {T = A; a = c; c =T;} if(b > C) {T = b; b = c; c =T;} printf ("%d%d%d\n", A, b, c); return 0;}View Code
Algorithmic Competition Introduction Classic _4_ branch structure programming