
- 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
C++ Program to Represent Linear Equations in Matrix Form
This is a C++ program to represent Linear Equations in matrix form.
Algorithm
Begin 1) Take the no of variables n and the coefficients of each variable as input. 2) Declare a matrix[n][n] and constant[n][1]. 3) Make for loops i = 0 to n-1 and j = 0 to n-1 to take the coefficients of each variable as the elements of the matrix. 4) Display the matrix by using nested for loops. End
Example
#include<iostream> using namespace std; int main(void) { char variable[] = { 'x', 'y', 'z', 'd' }; cout << "Enter the number of variables in the equations: "; int n; cin >> n; cout << "\nEnter the coefficients of each variable for each equation, ax + by + cz + ... = d:"; int matrix[n][n]; int constant[n][1]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> matrix[i][j]; } cin >> constant[i][0]; } cout << "Matrix representation is: "<<endl; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << " " << matrix[i][j]; } cout << " " << variable[i]; cout << " = " << constant[i][0]; cout << "\n"; } return 0; }
Output
Enter the number of variables in the equations: 3 Enter the coefficients of each variable for each equation, ax + by + cz + ... = d: 1 2 3 4 5 6 7 9 8 5 2 1 Matrix representation is: 1 2 3 x = 4 5 6 7 y = 9 8 5 2 z = 1
- Related Questions & Answers
- Solve a linear matrix equation or system of linear scalar equations in Python
- C++ Program to Represent Graph Using Adjacency Matrix
- C++ Program to Represent Graph Using Incidence Matrix
- Which linear function of SciPy is used to solve triangular matrix equations?
- C++ Program to Print Matrix in Z form?
- How to solve the simultaneous linear equations in R?
- Program to find coefficients of linear equations that has only one solution in Python
- Program to Print the Squared Matrix in Z form in C
- Python Program to Print Matrix in Z form
- Java Program to Print Matrix in Z form
- C Program to represent a multiplication table.
- How to solve banded matrix equations using Python SciPy?
- How to solve triangular matrix equations using Python SciPy?
- C/C++ Program for Number of solutions to Modular Equations?
- Program for Number of solutions to Modular Equations in C/C++?
Advertisements