আমাদের চিড়িয়াখানায় মোট মাথা এবং পা সংখ্যা দেওয়া আছে। এ থেকে হরিণ (৪ পা) এবং ময়ূর (২ পা) এর সংখ্যা বের করতে হবে।
উদাহরণ
ইনপুট: heads = 60, legs = 200
আউটপুট: Count of deers are: 40, Count of peacocks are: 20
ব্যাখ্যা
হরিণ = x, ময়ূর = y x + y = 60 (মাথা সমীকরণ) 4x + 2y = 200 (পা সমীকরণ) সমাধান: 4(60 - y) + 2y = 200 240 - 4y + 2y = 200 2y = 40 → y = 20 (ময়ূর) x = 60 - 20 = 40 (হরিণ)
দूसর উদাহরণ
ইনপুট: heads = 80, legs = 200
আউটপুট: Count of deers are: 20, Count of peacocks are: 60
সমাধানের পদ্ধতি
- মোট মাথা এবং পা ইনপুট নিন।
- হরিণের সংখ্যা =
((legs) - 2 * (heads)) / 2 - ময়ূরের সংখ্যা = মোট মাথা - হরিণের সংখ্যা।
- ফলাফল প্রিন্ট করুন।
প্রোগ্রাম উদাহরণ
#include <bits/stdc++.h>
using namespace std;
int countDeers(int heads, int legs) {
return ((legs) - 2 * (heads)) / 2;
}
int main() {
int heads = 80;
int legs = 200;
int deers = countDeers(heads, legs);
int peacocks = heads - deers;
cout << "Count of deers are: " << deers << endl;
cout << "Count of peacocks are: " << peacocks << endl;
return 0;
}
আউটপুট
Count of deers are: 20 Count of peacocks are: 60