Algorithmic Competition Introduction Classic _4_ branch structure programming

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.