GTU OOP Program - 2

2). Write a program that solves the following equation and displays the value x and y:
1) 3.4x+50.2y=44.5
2) 2.1x+.55y=5.9
(Assume Cramer’s rule to solve equation ax+by=e x=ed-bf/ad-bc cx+dy=f y=af-ec/ad-bc ).

Here we will create a general program and then add our equations as input

  1. import java.util.Scanner;
  2.  
  3. class Program_02 {
  4. public static void main(String[] args) {
  5.  
  6. Scanner input = new Scanner(System.in);
  7. System.out.println("Values of equation 1 :");
  8. System.out.print("Enter value of a : ");
  9. double a = input.nextDouble();
  10. System.out.print("Enter values of b : ");
  11. double b = input.nextDouble();
  12. System.out.print("Enter value of e : ");
  13. double e = input.nextDouble();
  14.  
  15. System.out.println("Values of Equation 2 : ");
  16. System.out.print("Enter value of c : ");
  17. double c = input.nextDouble();
  18. System.out.print("Enter value of d : ");
  19. double d = input.nextDouble();
  20. System.out.print("Enter value of f : ");
  21. double f = input.nextDouble();
  22.  
  23. // Using Cramer's rule
  24. double x = ((e * d) - (b * f)) / ((a * d) - (b * c));
  25. double y = ((a * f) - (e * c)) / ((a * d) - (b * c));
  26.  
  27. System.out.print("x = " + x + " y = " + y);
  28. }
  29. }
  30.  
Output
cse gtu, gtu study material for computer engineering students gujarat technological university oop lab manual solution

Comments

YouTube

Popular posts from this blog

GTU OS Program - 11 Filters

GTU OOP Program - 17 tic-tac-toe

GTU OS Program - 8