एक चर में किसी भी रैखिक समीकरण का रूप aX + b =cX + d होता है। यहाँ X का मान ज्ञात करना है, जब a, b, c, d के मान दिए गए हों।
एक चर में एक रैखिक समीकरण को हल करने का कार्यक्रम इस प्रकार है -
उदाहरण
#include<iostream>
using namespace std;
int main() {
float a, b, c, d, X;
cout<<"The form of the linear equation in one variable is: aX + b = cX + d"<<endl;
cout<<"Enter the values of a, b, c, d : "<<endl;
cin>>a>>b>>c>>d;
cout<<"The equation is "<<a<<"X + "<<b<<" = "<<c<<"X + "<<d<<endl;
if(a==c && b==d)
cout<<"There are infinite solutions possible for this equation"<<endl;
else if(a==c)
cout<<"This is a wrong equation"<<endl;
else {
X = (d-b)/(a-c);
cout<<"The value of X = "<< X <<endl;
}
} आउटपुट
उपरोक्त कार्यक्रम का आउटपुट इस प्रकार है
The form of the linear equation in one variable is: aX + b = cX + d Enter the values of a, b, c, d : The equation is 5X + 3 = 4X + 9 The value of X = 6
उपरोक्त कार्यक्रम में, पहले a, b, c और d के मान उपयोगकर्ता द्वारा इनपुट किए जाते हैं। फिर समीकरण प्रदर्शित होता है। यह नीचे दिया गया है -
cout<<"The form of the linear equation in one variable is: aX + b = cX + d"<<endl; cout<<"Enter the values of a, b, c, d : "<<endl; cin>>a>>b>>c>>d; cout<<"The equation is "<<a<<"X + "<<b<<" = "<<c<<"X + "<<d<<endl;
यदि a, c के बराबर है और b, d के बराबर है, तो समीकरण के अनंत हल हैं। यदि a, c के बराबर है, तो समीकरण गलत है। अन्यथा, X का मान परिकलित और मुद्रित किया जाता है। यह नीचे दिया गया है -
if(a==c && b==d)
cout<<"There are infinite solutions possible for this equation"<<endl;
else if(a==c)
cout<<"This is a wrong equation"<<endl;
else {
X = (d-b)/(a-c);
cout<<"The value of X = "<< X <<endl;
}