Skip to content

pavithrakuricheti534/Quadratic-roots

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Quadratic-roots

/*Lab. 1.1) Write a Java program to find the discriminant value D and find out the roots of

the quadratic equation of the form ax2+bx+c=0.*/

import java.util.*;

import java.lang.Math;

class QuadraticRoots {

public static void main(String[] args) {		

int a,b,c,d,deno;

	double x,r1,r2;

	Scanner s=new Scanner(System.in);

	System.out.print("Enter coefficients of quadratic equation:");

	a=s.nextInt();

	b=s.nextInt();

	c=s.nextInt();

	d=b*b-4*a*c;

	deno=2*a;

	x= Math.sqrt(d);

	if(d>=0)

	{

		if(d>0)

		{

			r1=(-b+x)/deno;

			r2=(-b-x)/deno;

			System.out.println("Roots are real and distint"+ " "+"r1="+r1+"   "+"r2="+r2);

		}

		else

		{

			r1=-b/deno;

			r2=-b/deno;

			System.out.println("Roots are real and equal"+ " "+"r1="+r1+"   "+"r2="+r2);

		}

	}

	else

	{

		System.out.println(" Roots are imaginary");

	}

}

} © 2021 GitHub, Inc.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published