Hello guys first what is a simultaneous equation: This
involves the calculation of more than one equation with unknowns
simultaneously.
Back to c-sharp programming, first you need to solve the equation in terms of its constants as shown below
Just like a pseudocode…..
Here is the code
using System;
namespace Simultaneous_Equation
{
class Program
{
static void
Main(string[] args)
{
Console.WriteLine("Welcome to Simultaneous Equation Solver");
//prints the message in the quote
string choice;
do
{
/*(multi line comment) a do loop= runs the code in the block and
then checks if the condition in the while loop is met to run again else it
breaks out of the loop*/
try
{
//try and catch looks for exception and the catches it, the
prints the //message in the catch block.
Console.WriteLine("Input in the format Ax + By = C");
Console.Write("x1= ");
int A
= int.Parse(Console.ReadLine());
Console.Write("y1= ");
int B
= int.Parse(Console.ReadLine());
Console.Write("c1= ");
int C
= int.Parse(Console.ReadLine());
Console.Write("x2= ");
int D
= int.Parse(Console.ReadLine());
Console.Write("y2= ");
int E
= int.Parse(Console.ReadLine());
Console.Write("c2= ");
int F
= int.Parse(Console.ReadLine());
float
x, y;
// equate the variable in terms of the constant
y =
((A * F) - (C * D)) / ((A * E) - (B * D));
if (A
== 0) { x = (F - (E * y)) / D; }
else {
x = (C - (B * y)) / A; }
Console.WriteLine("The value of x = {0}\nThe value of y =
{1}", x, y);
}
catch {
Console.WriteLine("Input is either wrong or not a simultaneous equation");
}
Console.WriteLine(" TRY AGAIN?? Type yes else quit");
choice =
Console.ReadLine().ToLower();
} while
(choice == "yes");
Console.ReadKey(true);
}
}
}
The formaular used here is wrong as it doesn't correspond when solved manually
ReplyDelete