0% found this document useful (0 votes)
42 views3 pages

Lab Manual Data Structures and Algorithms Name: Sana Shahzad CMS ID: 47417 Dept: Se-3 Submitted To: Sir Atif

This lab manual document contains an algorithm to solve quadratic equations and Java code to implement the algorithm. The algorithm takes coefficients A, B, C as input, calculates the discriminant D, and outputs the real solutions or indicates no real solutions. The Java code takes input for coefficients a, b, c, calculates discriminant using the formula, and outputs the solutions x1 and x2 or the message "No Real Solution" depending on the discriminant.

Uploaded by

sana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

Lab Manual Data Structures and Algorithms Name: Sana Shahzad CMS ID: 47417 Dept: Se-3 Submitted To: Sir Atif

This lab manual document contains an algorithm to solve quadratic equations and Java code to implement the algorithm. The algorithm takes coefficients A, B, C as input, calculates the discriminant D, and outputs the real solutions or indicates no real solutions. The Java code takes input for coefficients a, b, c, calculates discriminant using the formula, and outputs the solutions x1 and x2 or the message "No Real Solution" depending on the discriminant.

Uploaded by

sana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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");

You might also like