You are on page 1of 8

%Expt 2- Program to calculate the roots of quadratic equation

%Date-11/08/2014
clear all
clc
disp!"Enter the coefficients of quadratic equation"#
a$input!"Enter the first coefficient"#
%$input!"Enter the second coefficient "#
c$input!"Enter the third coefficient"#
d$%&2-4'a'c
p$!-%(d&0)*#/!2'a#
q$!-%-d&0)*#/!2'a#
if!!d+0#,,!%-$0##
disp!".oots are complex"#
elseif!!d+0#,,!%$$0##
disp!".oots are imaginar/"#
elseif!!d00#,,!%-$0##
disp!".oots are real and distinct"#
elseif!d$$0#
disp!".oots are equal"#
end

disp!"1he first root is2 "#
p
disp!"1he second root is2 "#
q
Solutions
Enter the coefcients of quadratic equation
Enter the frst coefcient1
Enter the second coefcient 2
Enter the third coefcient1
Roots are equal
The frst root is:
p =
-1
The second root is:
q =
-1
Enter the coefcients of quadratic equation
Enter the frst coefcient1
Enter the second coefcient -5
Enter the third coefcient6
Roots are real and distinct
The frst root is:
p =
3
The second root is:
q =
2
Enter the coefcients of quadratic equation
Enter the frst coefcient1
Enter the second coefcient
Enter the third coefcient6
Roots are co!ple"
The frst root is:
p =
-2#$$$$ % 1#12i
The second root is:
q =
-2#$$$$ - 1#12i
Enter the coefcients of quadratic equation
Enter the frst coefcient
Enter the second coefcient $
Enter the third coefcient16
Roots are i!a&inar'
The frst root is:
p =
$#$$$$ % 2#$$$$i
The second root is:
q =
-$#$$$$ - 2#$$$$i
Enter the coefcients of quadratic equation
Enter the frst coefcient1
Enter the second coefcient 2
Enter the third coefcient1
Roots are equal
The frst root is:
p =
-1
The second root is:
q =
-1
(f u )ant to run the pro&ra! a&ain* enter 1 else enter $ 1
Enter the coefcients of quadratic equation
Enter the frst coefcient1
Enter the second coefcient -5
Enter the third coefcient6
Roots are real and distinct
The frst root is:
p =
3
The second root is:
q =
2
(f u )ant to run the pro&ra! a&ain* enter 1 else enter $ 1
Enter the coefcients of quadratic equation
Enter the frst coefcient1
Enter the second coefcient
Enter the third coefcient6
Roots are co!ple"
The frst root is:
p =
-2#$$$$ % 1#12i
The second root is:
q =
-2#$$$$ - 1#12i
(f u )ant to run the pro&ra! a&ain* enter 1 else enter $ 1
Enter the coefcients of quadratic equation
Enter the frst coefcient
Enter the second coefcient $
Enter the third coefcient16
Roots are i!a&inar'
The frst root is:
p =
$#$$$$ % 2#$$$$i
The second root is:
q =
-$#$$$$ - 2#$$$$i
(f u )ant to run the pro&ra! a&ain* enter 1 else enter $ $

You might also like