LAB MANUAL
DATA STRUCTURES AND ALGORITHMS
NAME: SANA SHAHZAD
CMS ID: 47417
DEPT: SE-3
SUBMITTED TO: SIR ATIF
LAB 1:
Algorithm 2.2: i (Quadratic Equation) This algorithm inputs the coefficients A, B, C of a
quadratic equation and outputs the real solutions, if any.
* Step l. Read: A, B, C. , ,Step 2.a lf D>then: , (a) Set X7 '= ( -B +vD) /2A and X2:=(B- vD) /2A.
(b) Write:Xl, X2. Else if D = 0, then: (a) Set::B/2A. ' Else:
Write: ‘NO REAL SOLUTIONS' . [End of lf structure.] Step.4.Exit
CODE:
package javaapplication6;
import java.util.*;
public class JavaApplication6 {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int a,b,c;
System.out.println("Enter the value of a:");
a=scan.nextInt();
System.out.println("Enter the value of b:");
b=scan.nextInt();
System.out.println("Enter the value of c:");
c=scan.nextInt();
int D=(b*b)-(4*a*c);
int x1=(-b+D)/(2*a);
System.out.println(x1);
int x2=(-b-D)/(2*a);
System.out.println(x2);
if(D==0){
int x=b/2*a;
System.out.println("Unique Solution"+x);
}else{
System.out.println("No Real Solution");