रुपये में एक राशि दी गई है जिसका भुगतान करना है, मान लें pay_rupees और असीमित मात्रा में बैंकनोट्स हैं जिनका मान Rupees_amount_1 और Rupees_amount_2 के रूप में है। लक्ष्य pay_rupees का भुगतान ठीक कुल नोट्स की संख्या = distribution_total का उपयोग करके करना है और Rupees_amount_1 टाइप के नोट्स की संख्या गिनना है। यदि भुगतान करने का कोई समाधान नहीं है तो उत्तर के रूप में -1 लौटाएं।
उदाहरण के लिए
इनपुट
Rupees_amount_1 = 1, Rupees_amount_2 = 5, pay_Rupees = 11 distribution_total = 7
आउटपुट
Count of number of currency notes needed are - 6
व्याख्या
6*1 + 5*1 = 11 और नोट्स=6+1=7
इनपुट
Rupees_amount_1 = 2, Rupees_amount_2 = 3, pay_Rupees = 10 distribution_total = 4
आउटपुट
Count of number of currency notes needed are: 2
व्याख्या
2*2 + 3*2 = 10 और नोट्स=2+2=4
नीचे दिए गए प्रोग्राम में उपयोग किया गया दृष्टिकोण इस प्रकार है:
मान लें a1 राशि rupees 1 के नोट्स की संख्या है और N कुल नोट्स की संख्या है। P का भुगतान करने के लिए, हमारे पास समीकरण होंगे: a1*(Rupees_amount_1) + (N-a1)*(Rupees_amount_2) = P P=a1*(Rupees_amount_1) + (N)*(Rupees_amount_2) - (a1)*(Rupees_amount_2) P - (N)*(Rupees_amount_2) =a1*(Rupees_amount_1) - (a1)*(Rupees_amount_2) a1= P - (N)*(Rupees_amount_2) / ( Rupees_amount_1 - Rupees_amount_2) यदि a1 पूर्णांक है तो केवल हमारे पास एक समाधान होगा अन्यथा -1 लौटाएं।
सभी संख्याओं को इनपुट के रूप में लें।
फ़ंक्शन notes_needed(int Rupees_amount_1, int Rupees_amount_2, int pay_Rupees, int distribution_total) सभी इनपुट लेता है और आवश्यक करेंसी नोट्स की संख्या की गिनती लौटाता है।
प्रारंभिक गिनती को 0 के रूप में लें।
total = pay_Rupees - (Rupees_amount_2 * distribution_total) लें।
total_given = Rupees_amount_1 - Rupees_amount_2 सेट करें।
total_given = Rupees_amount_1 - Rupees_amount_2 सेट करें।
यदि total % total_given == 0 तो गिनती को total / total_given के रूप में लौटाएं।
अन्यथा -1 लौटाएं।
उदाहरण
#include<bits/stdc++.h> using namespace std; int notes_needed(int Rupees_amount_1, int Rupees_amount_2, int pay_Rupees, int distribution_total){ int count = 0; int total = pay_Rupees - (Rupees_amount_2 * distribution_total); int total_given = Rupees_amount_1 - Rupees_amount_2; if (total % total_given == 0){ count = total / total_given; return count; } else { return -1; } } int main(){ int Rupees_amount_1 = 1; int Rupees_amount_2 = 5; int pay_Rupees = 11; int distribution_total = 7; cout<<"Count of number of currency notes needed are: "<<notes_needed(Rupees_amount_1, Rupees_amount_2, pay_Rupees, distribution_total); } आउटपुट
यदि हम उपरोक्त कोड चलाते हैं तो यह निम्नलिखित आउटपुट उत्पन्न करेगा:
Count the number of currency notes needed are- 6