Head Count - Birds and Animals
In a zoo there are some birds and animals. All birds have two legs and all animals have four legs.
GIven the head count and leg count of both birds and animals taken together, the program must print the head count of birds and animals separated by a space as output.
GIven the head count and leg count of both birds and animals taken together, the program must print the head count of birds and animals separated by a space as output.
Input Format:
First line will contain the integer value H representing the head count of both birds and animals taken together.
Second line will contain the integer value L representing the leg count of both birds and animals taken together.
First line will contain the integer value H representing the head count of both birds and animals taken together.
Second line will contain the integer value L representing the leg count of both birds and animals taken together.
Output Format:
First line will contain the integer values of the head count of birds and animals separated by a space.
First line will contain the integer values of the head count of birds and animals separated by a space.
Constraints:
0 < H < 1000
1 < L < 2000
0 < H < 1000
1 < L < 2000
Sample Input/Output:
Example 1:
Input:
27
84
Input:
27
84
Output:
12 15
12 15
Explanation:
There are 12 birds and 15 animals.
There are 12 birds and 15 animals.
Example 2:
Input:
114
256
Input:
114
256
Output:
100 14
100 14
Explanation:
There are 100 birds and 14 animals.
Code:
Logic 1:
Logic 2:
There are 100 birds and 14 animals.
Code:
Logic 1:
#include<iostream>
using namespace std;
int main(int argc, char**
argv)
{
int a,b;
cin>>a>>b;
cout<<abs((b-(4*a))/2)<<"
";
cout<<abs((b-(2*a))/2);
}
#include <iostream>
using namespace std;
int main(int argc, char**
argv)
{
int head,leg,i,j,flag=0;
cin>>head>>leg;
for(i=1;i<head;i++)
{
for(j=leg;j>1;j--)
{
if(leg==(i*2)+(j*4))
{
if(head==i+j)
{
cout<<i<<"
"<<j;
flag=1;
break;
}
}
}
if(flag==1)
break;
}
}
Please do comment If u have any Queries!
#include
ReplyDelete#include
using namespace std;
int main(int argc, char** argv)
{
int a,b;
cin>>a>>b;
cout<<abs((b-(4*a))/2)<<" ";
cout<<abs((b-(2*a))/2);
}
adaiii java la kudunga da
ReplyDelete