কম্পিউটার

C++ এ প্রদত্ত মাথা ও পায়ের সংখ্যা থেকে চিড়িয়াখানায় প্রাণীর সংখ্যা গণনা করুন


আমাদের একটি চিড়িয়াখানায় মোট মাথা এবং পায়ের সংখ্যা দেওয়া হয় এবং কাজটি হল প্রদত্ত ডেটা দিয়ে চিড়িয়াখানায় মোট প্রাণীর সংখ্যা গণনা করা। নীচের প্রোগ্রামে আমরা প্রাণীদের হরিণ এবং ময়ূর হিসাবে বিবেচনা করছি।

ইনপুট৷ −

heads = 60
legs = 200

আউটপুট

Count of deers are: 40
Count of peacocks are: 20

ব্যাখ্যা

let total number of deers to be : x
Let total number of peacocks to be : y
As head can be only one so first equation will be : x + y = 60
And deers have 4 legs and peacock have 2 legs so second equation will be : 4x + 2y = 200
Solving equations then it will be:
4(60 - y) + 2y = 200
240 - 4y + 2y = 200
y = 20 (Total count of peacocks)
x = 40(Total count of heads - total count of peacocks)

ইনপুট

heads = 80
Legs = 200

আউটপুট

Count of deers are: 20
Count of peacocks are: 60

ব্যাখ্যা

let total number of deers to be : x
Let total number of peacocks to be : y
As head can be only one so first equation will be : x + y = 80
And deers have 4 legs and peacock have 2 legs so second equation will be : 4x + 2y = 200
Solving equations then it will be:
4(80 - y) + 2y = 200
320 - 4y + 2y = 200
y = 60 (Total count of peacocks)
x = 20(Total count of heads - total count of peacocks)

নিম্নলিখিত প্রোগ্রামে ব্যবহৃত পদ্ধতি

  • একটি চিড়িয়াখানায় মাথা এবং পায়ের মোট সংখ্যা ইনপুট করুন

  • হরিণ গণনা করার জন্য একটি ফাংশন তৈরি করুন

  • ফাংশনের ভিতরে, গণনা সেট করুন ((পা)-2 * (মাথা))/2

  • গণনা ফেরত দিন

  • এখন, চিড়িয়াখানায় মোট মাথার সংখ্যা থেকে হরিণের মোট সংখ্যা বিয়োগ করে ময়ূর গণনা করুন।

  • ফলাফল প্রিন্ট করুন।

উদাহরণ

#include <bits/stdc++.h>
using namespace std;
// Function that calculates count for deers
int count(int heads, int legs){
   int count = 0;
   count = ((legs)-2 * (heads))/2;
   return count;
}
int main(){
   int heads = 80;
   int legs = 200;
   int deers = count(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

  1. C++ এ প্রদত্ত সংখ্যা দ্বারা বিভাজ্য n সংখ্যার সংখ্যা গণনা করুন

  2. C++ এ প্রদত্ত N এর সাথে 1 যোগ করার পর পরিবর্তিত বিটের সংখ্যা গণনা করা হয়েছে

  3. C++ এ প্রদত্ত পরিসর থেকে সর্বাধিক বিটওয়াইজ এবং জোড়া

  4. C++ এ প্রদত্ত পথ থেকে স্টপের ন্যূনতম সংখ্যা