यह एक C++ प्रोग्राम है जो रैखिक समीकरणों को मैट्रिक्स रूप में प्रस्तुत करता है।
एल्गोरिदम
Begin 1) चरों की संख्या n और प्रत्येक चर के गुणांक को इनपुट के रूप में लें। 2) एक मैट्रिक्स matrix[n][n] और constant[n][1] डिक्लेयर करें। 3) प्रत्येक चर के गुणांक को मैट्रिक्स के तत्वों के रूप में लेने के लिए i = 0 से n-1 और j = 0 से n-1 तक फॉर लूप बनाएं। 4) नेस्टेड फॉर लूप का उपयोग करके मैट्रिक्स प्रदर्शित करें। End
उदाहरण
#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; }
आउटपुट
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