Computer Science‎ > ‎

C Program: Solving Simultaneous Equations in Two Variables



 
The C++ Programming Language...
List Price: Rs.775
Our Price: Rs.736
Buy from FlipKart

The C++ Programming Language (Bjarne Stroustrup)

Beginning C++ Through Game Pr...
Our Price: Rs.2008
Buy from FlipKart

       
Beginning C++ through Game Programming 

 
C++ How to Program
List Price: Rs.695
Our Price: Rs.632
Buy from FlipKart

                               
 
The C Programming Language
List Price: Rs.175
Our Price: Rs.137
Buy from FlipKart

             
The C Programming Language (Kernighan)
 
C How To Program 6th  Edition
List Price: Rs.650
Our Price: Rs.624
            Buy from FlipKart


          
C How to Program (Deitel and Deitel)

 



C Program source code to solve Simultaneous Linear Equations in two variables


/*The following program finds out the solutions to simultaneous equation in two variables.The equations are of the form
ax+by=c and px+qy=r.
The coefficents of the 2 equations are taken as input and we evaluate the unknown x and y accordingly.
*/
#include<stdio.h>
int main()
{
double a,b,c,p,q,r,x,y;
printf("Enter the coefficents of the first equation of the form ax+by=c\n");
scanf("%lf%lf%lf",&a,&b,&c);//The coefficents of the first equation
printf("Enter the coefficents of the second equation of the form px+qy=r\n");
scanf("%lf%lf%lf",&p,&q,&r);//The coefficents of the second equation
if(((a*q-p*b)!=0)&&((b*p-q*a)!=0))
{//In this case we have a unique solution and display x and y
printf("The solution to the equations is unique\n");
x=(c*q-r*b)/(a*q-p*b);
y=(c*p-r*a)/(b*p-q*a);
printf("The value of x=%lf\n",x);
printf("The value of y=%lf\n",y);
}
else
if(((a*q-p*b)==0)&&((b*p-q*a)==0)&&((c*q-r*b)==0)&&((c*p-r*a)==0))//In such condition we can have infinitely many solutions to the equation.
{//When we have such a condition than mathematically we can choose any one unknown as free and other unknown can be calculated using the free variables's value.
//So we choose x as free variable and then get y
    printf("Infinitely many solutions are possible\n");
    printf("The value of x can be varied and y can be calculated according to x's value using relation\n");
    printf("y=%lf+(%lf)x",(c/b),(-1*a/b));
}
else
if(((a*q-p*b)==0)&&((b*p-q*a)==0)&&((c*q-r*b)!=0)&&((c*p-r*a)!=0))//In such condition no solutions are possible.
printf("No solutions are possible\n");
getch();
}
/*A sample run of the program was carried out and the results found were as follows:-
Enter the coefficents of the first equation of the form ax+by=c
2 4 6
Enter the coefficents of the second equation of the form px+qy=r
3 6 9
Infinitely many solutions are possible
The value of x can be varied and y can be calculated according to x's value using relation
y=1.500000+(-0.500000)x
*/








 














C Program to Reverse A String

C Program: Building an Expression Evaluator
C Program: Check for Armstrong Numbers
C Program: Check whether a string is a Palindrome or not
C Program: Common Operations on Sets - Union, Intersection, Difference, Cardinal Product
C Program: Computing exp(x), sin(x), cos(x), tan(x) using series expansions
C Program: Computing the Area of a Circle
C Program: Computing the Upper Triangular Matrix and Lower Triangular Matrix
C Program: Demonstrating File Handling Functions
C Program: Demonstrating Operations on Matrices - Addition, Subtraction, Multiplication, Inversion, Finding Determinants
C Program: Demonstrating the use of Bitwise Operators
C Program: Displaying a Histogram of word frequencies (unigram)
C Program: Distance Vector Routing Algorithm using Bellman Ford's Algorithm
C Program: Numerical Computing - The Gaussian Elimination Method
C Program: Numerical Computing - Implementing the Newton Raphson Method
C Program: Numerical Computing - the Bisection Method
C Program: Numerical Computing - The Gaussian Elimination Technique from Linear Algebra
C Program: Numerical Computing - the Jacobi Method
C Program: Printing the Pascal Triangle
C Program: Reversing the order of words in a sentence
C Program: Solving Simultaneous Equations in Two Variables
C Program: Source Code for computing the GCD(HFC) of two numbers
C Program: Source Code for Solving Quadratic Equations
C Program: Source code to solve the Josephus Problem
C Program: Sudoku Solver
C Program: The Usage of Command Line Arguments
C Program: Using the Sieve of Eratosthenes to print Prime Numbers