0% found this document useful (0 votes)
31 views

Experiment:1.1: Studentname: Uid: Branch: Section/Group: Semester: Date Ofperformance: Subject Name: Subject Code

The document describes an experiment to write a program that finds the roots of a quadratic equation. It includes the aim, tasks, algorithm, steps, sample code, and expected output. The algorithm takes in coefficients a, b, c and calculates the discriminant to determine if the roots are real, equal, or complex. If real, it calculates and prints the two roots. If equal, it calculates and prints the single root. If complex, it calculates and prints the real and imaginary parts of the two roots.

Uploaded by

Eknoor Singh
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)
31 views

Experiment:1.1: Studentname: Uid: Branch: Section/Group: Semester: Date Ofperformance: Subject Name: Subject Code

The document describes an experiment to write a program that finds the roots of a quadratic equation. It includes the aim, tasks, algorithm, steps, sample code, and expected output. The algorithm takes in coefficients a, b, c and calculates the discriminant to determine if the roots are real, equal, or complex. If real, it calculates and prints the two roots. If equal, it calculates and prints the single root. If complex, it calculates and prints the real and imaginary parts of the two roots.

Uploaded by

Eknoor Singh
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/ 8

EXPERIMENT:1.

StudentName: UID:
Branch: Section/Group:
Semester: Date ofPerformance:
Subject Name: Subject Code:

1. Aim/Overview of thepractical: Write a program to find roots of quadratic equation

2. Task to bedone:Write a program to find roots of quadratic equation

3. Algorithm/Flowchart:

 Create a scanner class object

 Take 3 double value input

fromuser

 Calculate Discriminant with the

formula(sqrt(b*b-4*a*c))

 Check:-

 if discriminant greater than zero roots will be real anddifferent


 if discriminant equals zero roots will be same andreal
 if discriminant less than zero roots will be complex and different
 Print the result
4. Steps forexperiment/practical:
 Take Input from User

 Remember a cannot
bezero

 Find roots with the help


ofAboveAlgorithm

 Print the Result


3. CODE:

import java.util.Scanner;

public class one{

public static void main(String[] args)

{ Scanner sc = new Scanner(System.in);

System.out.println("Enter Value of a:");

double a = sc.nextDouble();

if(a==0){

System.out.println("a Cannot be Zero");

}
else{

System.out.println("Enter Value of b:");

double b = sc.nextDouble();

System.out.println("Enter Value of c:");

double c = sc.nextDouble();

double determinant = (b*b)-(4*a*c);

double sqroot = Math.sqrt(determinant);

double r1,r2;

if(determinant>0){

System.out.println("\nRoot's Are Real and Different:");

r1 = (-b + sqroot)/(2*a);

r2 = (-b - sqroot)/(2*a);

System.out.format("Root1 = %.2f \nRoot2 = %.2f", r1, r2);

else if(determinant==0){

System.out.println("\nRoot's Are Real and Equal:");

r1=r2 = -b/(2*a);

System.out.format("Root1 = %.2f \nRoot2 = %.2f",r1,r2);

else{

System.out.println("\nRoot's Are Complex and Different:");

double real = -b/(2*a);


double imaginary = Math.sqrt(-determinant)/(2*a);

System.out.format("Root-1 = %.2f + %.2fi\n",real,imaginary);

System.out.format("Root-2 = %.2f - %.2fi\n",real,imaginary);

4. Image of sample output to be attachedhere


BEFARTME9T0F N A A C A
GR A D E¥
Discover. Learn. Empower.
«
*W I•
ACCREDITED UNIVERSITY
Learning outcomes (What I have learnt):

1. Use of ScannerClass

2. Java Syntax

3. Use of ConditionalStatement

4. Java Input and OutputFunctions

5. Arithmetic operation and MathClass


Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
2.
3.
BEFARTME9T0F N A A C A
GR A D E¥
cu ) Discover. Learn. Empower.
«
*W I•
ACCREDITED UNIVERSITY

You might also like