Chicken and rabbit cage

Source: Internet
Author: User

/*describes the total number of chickens and rabbits known to be n and the total number of legs m. Enter n and m, output the number of chickens and rabbits in turn, and if no solution, output "no answer" (no quotation marks). Enter the first line to enter a data a, representing the next few sets of data, in the next (a<10) a row, each row has a N and M. (0<m,n<100) output number of chickens or rabbits, or no answer sample input 214 3210 16 Sample output 2No answer*//*2 2 No answer*/#include<stdio.h>intMainintargcConst Char*argv[]) {    //Insert code here ...     intn,m,flag=0, num; scanf ("%d",&num);  while(num--) {scanf ("%d%d",&n,&m);  for(intx=0;x< -; x + +) {             for(inty=0;y< -; y++) {                if((x+y) ==n&& (2*x+4*y) = =m) {flag=1; printf ("%d%d\n", x, y); }            }        }        if(flag==0) {printf ("No answer\n"); } Flag=0; }    return 0;}

Chicken and rabbit cage

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: 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.