summaryrefslogtreecommitdiff
path: root/659/CH9/EX9.4/exm9_4.sci
diff options
context:
space:
mode:
Diffstat (limited to '659/CH9/EX9.4/exm9_4.sci')
-rwxr-xr-x659/CH9/EX9.4/exm9_4.sci23
1 files changed, 23 insertions, 0 deletions
diff --git a/659/CH9/EX9.4/exm9_4.sci b/659/CH9/EX9.4/exm9_4.sci
new file mode 100755
index 000000000..6b8d2abde
--- /dev/null
+++ b/659/CH9/EX9.4/exm9_4.sci
@@ -0,0 +1,23 @@
+// Example 9.4
+//Write a program with function power that computes x raised to the power y.
+funcprot(0);
+function p = power(x,y)
+ p=1.0; // x to power 0
+ if((y>=0)) then
+ while(y) //computes positive powers
+ p=p*x;
+ y=y-1;
+ end
+ else
+ while(y) //computes negative powers
+ p=p/x;
+ y=y+1;
+ end
+ end
+endfunction
+disp("Enter x,y:");
+disp("[Enter in single line seperated by space] ");
+[x,y]=scanf("%d %d"); //input using scanf function
+
+//calling power() function and printing its output
+printf("%d to the power %d is %f",x,y,power(x,y));