summaryrefslogtreecommitdiff
path: root/964/CH2/EX2.1/2_1.sce
diff options
context:
space:
mode:
Diffstat (limited to '964/CH2/EX2.1/2_1.sce')
-rwxr-xr-x964/CH2/EX2.1/2_1.sce32
1 files changed, 32 insertions, 0 deletions
diff --git a/964/CH2/EX2.1/2_1.sce b/964/CH2/EX2.1/2_1.sce
new file mode 100755
index 000000000..b27c3f203
--- /dev/null
+++ b/964/CH2/EX2.1/2_1.sce
@@ -0,0 +1,32 @@
+clc;
+clear;
+response=1;
+while response==1
+a=input("Input the value of a:")
+b=input("Input the value of b:")
+c=input("Input the value of c:")
+if a==0 then
+ if b~=0 then
+ r1=-c/b;
+ disp(r1,"The root:")
+ else disp("Trivial Solution.")
+ end
+else
+ discr=b^2-4*a*c;
+ if discr>=0 then
+ r1=(-b+sqrt(discr))/(2*a);
+ r2=(-b-sqrt(discr))/(2*a);
+ disp(r2,"and",r1,"The roots are:")
+ else
+ r1=-b/(2*a);
+ r2=r1;
+ i1=sqrt(abs(discr))/(2*a);
+ i2=-i1;
+ disp(r2+i2*sqrt(-1),r1+i1*sqrt(-1),"The roots are:")
+ end
+end
+response=input("Do you want to continue (press 1 for yes and 2 for no)?")
+if response=2 then exit;
+end
+end
+end \ No newline at end of file