কম্পিউটার টিউটোরিয়াল

এক চলকযুক্ত যেকোনো রৈখিক সমীকরণ সমাধানের C++ প্রোগ্রাম


এক চলকযুক্ত যেকোনো রৈখিক সমীকরণের রূপ হয় aX + b = cX + d। এখানে a, b, c, d-এর মান দেওয়া থাকলে X-এর মান বের করতে হয়।

এক চলকযুক্ত রৈখিক সমীকরণ সমাধানের একটি প্রোগ্রাম নিচে দেওয়া হলো:

উদাহরণ

#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;
    }
    return 0;
}

আউটপুট

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;
}

  1. আংশিকভাবে ভরা সুডোকু গ্রিড সমাধান C++-এ

  2. C++-এ DAG-এর জন্য র‍্যান্ডম লিনিয়ার এক্সটেনশন (Random Linear Extension) তৈরি করা

  3. যেকোনো ম্যাট্রিক্সের LU ডিকম্পোজিশনের C++ প্রোগ্রাম

  4. C++ প্রোগ্রাম: দ্বিঘাত সমীকরণের মূল (Roots) নির্ণয়