This is a C++ Program to represent a set of linear equations in matrix form.
Here is source code of the C++ Program to Represent Linear Equations in Matrix Form. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
#include<iostream>
#include<conio.h>
using namespace std;
int main(void)
{
char var[] = { 'x', 'y', 'z', 'w' };
cout << "Enter the number of variables in the equations: ";
int n;
cin >> n;
cout << "\nEnter the coefficients of each variable for each equations";
cout << "\nax + by + cz + ... = d";
int mat[n][n];
int constants[n][1];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> mat[i][j];
}
cin >> constants[i][0];
}
cout << "Matrix representation is: ";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << " " << mat[i][j];
}
cout << " " << var[i];
cout << " = " << constants[i][0];
cout << "\n";
}
return 0;
}
Output:
$ g++ MatrixRepOfEquations.cpp $ a.out Enter the number of variables in the equations: 3 Enter the coefficients of each variable for each equations ax + by + cz + ... = d 1 2 3 4 1 2 6 8 2 3 9 8 Matrix representation is: 1 2 3 x = 4 1 2 6 y = 8 2 3 9 z = 8
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
Here’s the list of Best Books in C++ Programming, Data Structures and Algorithms.
Next Steps:
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Buy Computer Science Books
- Practice Programming MCQs
- Apply for Information Technology Internship
- Apply for Computer Science Internship
- Practice Computer Science MCQs