Count Number of animals in a zoo from given number of head and legs | C ++ implementation of above approach ; Function that calculates Rabbits ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countRabbits ( int Heads , int Legs ) { int count = 0 ; count = ( Legs ) -2 * ( Heads ) ; count = count / 2 ; return count ; } int main ( ) { int Heads = 100 , Legs = 300 ; int Rabbits = countRabbits ( Heads , Legs ) ; cout << " Rabbits ▁ = ▁ " << Rabbits << endl ; cout << " Pigeons ▁ = ▁ " << Heads - Rabbits << endl ; return 0 ; }