Proxy > Gmail Facebook Yahoo!

32. Write a program that will read the values of constants a, b, c, d, m and n and compute the values of x1 and x2. An appropriate message should be printed if ad – cb = 0




  1. A set of two linear equations with two unknowns x1 and x2 is given below:
ax1 + bx2 = m
cx1 + dx2 = n
            The set has a unique solution
           
            x1 =  (md - bn)/(ad - cb)
            x2 = (na - mc) / (ad - cb)

            provided the denominator ad –cb is not equal to zero.
            Write a program that will read the values of constants a, b, c, d, m and n and compute the values of x1 and x2. An appropriate message should be printed if ad – cb = 0

 import java.util.*;
public class LinearEquation {
 
 
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    System.out.print("Enter the value of a=");
    int a = scan.nextInt();
    System.out.print("Enter the value of b=");
    int b = scan.nextInt();
    System.out.print("Enter the value of c=");
    int c = scan.nextInt();
    System.out.print("Enter the value of d=");
    int d = scan.nextInt();
    System.out.print("Enter the value of m=");
    int m = scan.nextInt();
    System.out.print("Enter the value of n=");
    int n = scan.nextInt();
    if (a * d == c * b) {
      System.out.println("denominator  is Zero cant calculate");
    } else {
      double x1 = (m * d - b * n) / (a * d - c * b);
      double x2 = (n * a - m * c) / (a * d - c * b);
      System.out.println("Value of x1="+x1);
      System.out.println("Value of x2="+x2);
    }
  
  }
  
}


Responses

0 Respones to "32. Write a program that will read the values of constants a, b, c, d, m and n and compute the values of x1 and x2. An appropriate message should be printed if ad – cb = 0"


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar