If there are m heads and n feet. How to write program to display no of cows and no of men found?

Sample input 1: 3 10 Sample output 1: Cows :2 Men :1 Sample input 2: 10 44 Sample output 2: Invalid input

4/4/2020 6:07:37 AM


3 Answers

New Answer


Roshini Cow + Men = m.........(1) 4*Cow +2*Men = n............(2) Solve these two equation to find Cow and Men. And if n>4*m , then invalid input.


Cow=(n-2*m)/2; Men=m-(n-2*m)/2; After solving


Hi Roshini I don't normally like to post a complete answer, but if you wish, there is an option here. https://code.sololearn.com/c2qtBl37cpV7/?ref=app