Users Online
· Guests Online: 112
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
C Program to Represent Linear Equations in Matrix Form
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char var[] = { 'x', 'y', 'z', 'w' };
printf("Enter the number of variables in the equations: ");
int n;
scanf("%d", &n);
printf("\nEnter the coefficients of each variable for each equations");
printf("\nax + by + cz + ... = d");
int mat[n][n];
int constants[n][1];
int i,j;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &mat[i][j]);
}
scanf("%d", &constants[i][0]);
}
printf("Matrix representation is: ");
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
printf(" %f", mat[i][j]);
}
printf(" %f", var[i]);
printf(" = %f", constants[i][0]);
printf("\n");
}
return 0;
}
Output:
$ gcc MatRepOfEquation.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
#include <stdlib.h>
int main(void)
{
char var[] = { 'x', 'y', 'z', 'w' };
printf("Enter the number of variables in the equations: ");
int n;
scanf("%d", &n);
printf("\nEnter the coefficients of each variable for each equations");
printf("\nax + by + cz + ... = d");
int mat[n][n];
int constants[n][1];
int i,j;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &mat[i][j]);
}
scanf("%d", &constants[i][0]);
}
printf("Matrix representation is: ");
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
printf(" %f", mat[i][j]);
}
printf(" %f", var[i]);
printf(" = %f", constants[i][0]);
printf("\n");
}
return 0;
}
Output:
$ gcc MatRepOfEquation.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
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.