0% found this document useful (0 votes)
44 views4 pages

Linear

This program solves systems of linear equations for 2 or 3 unknown variables. The user selects whether to solve 2 equations with 2 unknowns or 3 equations with 3 unknowns. Based on the user input, the program prompts for the coefficients of the equations and computes the unknown variables by calculating the determinant and substituting back into the equations. It then displays the solutions.

Uploaded by

Ruth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views4 pages

Linear

This program solves systems of linear equations for 2 or 3 unknown variables. The user selects whether to solve 2 equations with 2 unknowns or 3 equations with 3 unknowns. Based on the user input, the program prompts for the coefficients of the equations and computes the unknown variables by calculating the determinant and substituting back into the equations. It then displays the solutions.

Uploaded by

Ruth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

LINEAR EQUATION

/* This program will compute for the 2 or 3 unknown depending on the user chice */
#include<stdio.h>
#include<conio.h>
float x1,x2,x3,y2,y3,z1,z2,z3,D,x,y,z,choice,e1,e2,e3,c1,c2,c3,y1,X,Y,Z;
main()
{
printf(" 1- two equations two unknown 4- three equation three unknown");
printf("\n____________________________________________________________________________");
printf("\n Enter Your choice");
scanf("%f",&choice);
if (choice ==1){
printf("\n____________________________________________________________________________");
printf ("\n Enter x1:");
scanf("%f",&x1);
printf ("\n Enter y1:");
scanf("%f",&y1);
printf ("\n Enter c1:");
scanf("%f",&c1);
printf ("\n Enter x2:");
scanf("%f",&x2);
printf ("\n Enter y2:");
scanf("%f",&y2);
printf ("\n Enter c2:");
scanf("%f",&c2);
printf("\n____________________________________________________________________________");
printf("\n First Equation: %0.12fx +(%0.12fy) =%0.12f ",x1,y1,c1);
printf("\n Second Equation: %0.12fx +(%0.12fy) =%0.12f ",x2,y2,c2);
D = (x1*y2)-(x2*y1);
x = ((c1*y2)-(c2*y1));
y =((x1*c2)-(x2*c1));
X=x/D;
Y=y/D;
printf("\n____________________________________________________________________________");
printf("\nThe Unknowns Are:");
printf("\nx = %f",X);
printf("\ny = %f",Y);
printf("\n____________________________________________________________________________");
}
else if( choice == 4){
printf("\n____________________________________________________________________________");
printf ("\n Enter x1:");
scanf("%f",&x1);
printf ("\n Enter y1:");
scanf("%f",&y1);
printf ("\n Enter z1:");
scanf("%f",&z1);
printf ("\n Enter c1:");
scanf("%f",&c1);
printf ("\n Enter x2:");
scanf("%f",&x2);
printf ("\n Enter y2:");
scanf("%f",&y2);
printf ("\n Enter z2:");
scanf("%f",&z2);
printf ("\n Enter c2:");
scanf("%f",&c2);
printf ("\n Enter x3:");
scanf("%f",&x3);
printf ("\n Enter y3:");
scanf("%f",&y3);
printf ("\n Enter z3:");
scanf("%f",&z3);
printf ("\n Enter c3:");
scanf("%f",&c3);
printf("\n____________________________________________________________________________");
printf("\n First Equation: %0.12fx +(%0.12fy)+(%0.12fz) =%0.12f ",x1,y1,z1,c1);
printf("\n Second Equation: %0.12fx +(%0.12fy)+(%0.12fz) =%0.12f ",x2,y2,z2,c2);
printf("\n Third Equation: %0.12fx +(%0.12fy)+(%0.12fz) =%0.12f ",x3,y3,z3,c3);
printf("\n____________________________________________________________________________");
D = (((x1*y2*z3)+(y1*z2*x3)+(z1*x2*y3)))-(((x3*y2*z1)+(y3*z2*x1)+(z3*x2*y1)));
x= ((c1*y2*z3)+(y1*z2*c3)+(z1*c2*y3))-((c3*y2*z1)+(y3*z2*c1)+(z3*c2*y1));
y= ((x1*c2*z3)+(c1*z2*x3)+(z1*x2*c3))-((x3*c2*z1)+(c3*z2*x1)+(z3*x2*c1));
z= ((x1*y2*c3)+(y1*c2*x3)+(c1*x2*y3))-((x3*y2*c1)+(y3*c2*x1)+(c3*x2*y1));
X = x/D;
Y= y/D;
Z= z/D;
printf("\n____________________________________________________________________________");
printf("\nThe Unknowns Are:");
printf("\nx = %f",X);
printf("\ny = %f",Y);
printf("\nz = %f",Z);
printf("\n____________________________________________________________________________");
}
else{
printf("\n____________________________________________________________________________");
printf("\nTry Again");
printf("\n____________________________________________________________________________");
}
scanf("%d");
return 0;}
LINEAR EQUATION
/* This program will compute for the 2 or 3 unknown depending on the user chice */
#include<stdio.h>
#include<conio.h>
float x1,x2,x3,y2,y3,z1,z2,z3,D,x,y,z,choice,e1,e2,e3,c1,c2,c3,y1,X,Y,Z;
main()
{
printf(" 5- two equations two unknown 8- three equation three unknown");
printf("\n____________________________________________________________________________");
printf("\n Enter Your choice");
scanf("%f",&choice);
if (choice ==5){
printf("\n____________________________________________________________________________");
printf ("\n Enter x1:");
scanf("%f",&x1);
printf ("\n Enter y1:");
scanf("%f",&y1);
printf ("\n Enter c1:");
scanf("%f",&c1);
printf ("\n Enter x2:");
scanf("%f",&x2);
printf ("\n Enter y2:");
scanf("%f",&y2);
printf ("\n Enter c2:");
scanf("%f",&c2);
printf("\n____________________________________________________________________________");
printf("\n First Equation: %0.12fx +(%0.12fy) =%0.12f ",x1,y1,c1);
printf("\n Second Equation: %0.12fx +(%0.12fy) =%0.12f ",x2,y2,c2);
D = (x1*y2)-(x2*y1);
x = ((c1*y2)-(c2*y1));
y =((x1*c2)-(x2*c1));
X=x/D;
Y=y/D;
printf("\n____________________________________________________________________________");
printf("\nThe Unknowns Are:");
printf("\nx = %f",X);
printf("\ny = %f",Y);
printf("\n____________________________________________________________________________");
}
else if( choice == 8){
printf("\n____________________________________________________________________________");
printf ("\n Enter x1:");
scanf("%f",&x1);
printf ("\n Enter y1:");
scanf("%f",&y1);
printf ("\n Enter z1:");
scanf("%f",&z1);
printf ("\n Enter c1:");
scanf("%f",&c1);
printf ("\n Enter x2:");
scanf("%f",&x2);
printf ("\n Enter y2:");
scanf("%f",&y2);
printf ("\n Enter z2:");
scanf("%f",&z2);
printf ("\n Enter c2:");
scanf("%f",&c2);
printf ("\n Enter x3:");
scanf("%f",&x3);
printf ("\n Enter y3:");
scanf("%f",&y3);
printf ("\n Enter z3:");
scanf("%f",&z3);
printf ("\n Enter c3:");
scanf("%f",&c3);
printf("\n____________________________________________________________________________");
printf("\n First Equation: %0.12fx +(%0.12fy)+(%0.12fz) =%0.12f ",x1,y1,z1,c1);
printf("\n Second Equation: %0.12fx +(%0.12fy)+(%0.12fz) =%0.12f ",x2,y2,z2,c2);
printf("\n Third Equation: %0.12fx +(%0.12fy)+(%0.12fz) =%0.12f ",x3,y3,z3,c3);
printf("\n____________________________________________________________________________");
D = (((x1*y2*z3)+(y1*z2*x3)+(z1*x2*y3)))-(((x3*y2*z1)+(y3*z2*x1)+(z3*x2*y1)));
x= ((c1*y2*z3)+(y1*z2*c3)+(z1*c2*y3))-((c3*y2*z1)+(y3*z2*c1)+(z3*c2*y1));
y= ((x1*c2*z3)+(c1*z2*x3)+(z1*x2*c3))-((x3*c2*z1)+(c3*z2*x1)+(z3*x2*c1));
z= ((x1*y2*c3)+(y1*c2*x3)+(c1*x2*y3))-((x3*y2*c1)+(y3*c2*x1)+(c3*x2*y1));
X = x/D;
Y= y/D;
Z= z/D;
printf("\n____________________________________________________________________________");
printf("\nThe Unknowns Are:");
printf("\nx = %f",X);
printf("\ny = %f",Y);
printf("\nz = %f",Z);
printf("\n____________________________________________________________________________");
}
else{
printf("\n____________________________________________________________________________");
printf("\nTry Again");
printf("\n____________________________________________________________________________");
}
scanf("%d");
return 0;
}

You might also like