- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Any linear equation in one variable has the form aX + b = cX + d. Here the value of X is to be found, when the values of a, b, c, d are given.

A program to solve a linear equation in one variable is as follows −

#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 output of the above program is as follows

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

In the above program, first the values of a, b, c and d are input by the user. Then the equation is displayed. This is given below −

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 is equal to c and b is equal to d, then there are infinite solutions for the equation. If a is equal to c, then the equation is wrong. Otherwise, the value of X is calculated and printed. This is given below −

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

- Related Questions & Answers
- Secant method to solve non-linear equation
- C program to find the solution of linear equation
- How to Solve Quadratic Equation using Python?
- How to solve the simultaneous linear equations in R?
- C++ Program to Solve N-Queen Problem
- Find number of solutions of a linear equation of n variables in C++
- Write a C# program to solve FizzBuzz problem
- C++ Program to Solve the Fractional Knapsack Problem
- C++ Program to Solve the Dominating Set Problem
- Program to solve partially filled Sudoku Grid in C++
- C++ Program to implement Linear Extrapolation
- C program to compute linear regression
- C++ Program to Solve the 0-1 Knapsack Problem
- C++ Program to Solve Knapsack Problem Using Dynamic Programming
- C/C++ Program for Linear Search?

Advertisements