diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /659/CH9/EX9.4 | |
download | Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2 Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip |
initial commit / add all books
Diffstat (limited to '659/CH9/EX9.4')
-rwxr-xr-x | 659/CH9/EX9.4/exm9_4.sci | 23 | ||||
-rwxr-xr-x | 659/CH9/EX9.4/exm9_4_output.PNG | bin | 0 -> 15533 bytes |
2 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));
diff --git a/659/CH9/EX9.4/exm9_4_output.PNG b/659/CH9/EX9.4/exm9_4_output.PNG Binary files differnew file mode 100755 index 000000000..e64d3ed42 --- /dev/null +++ b/659/CH9/EX9.4/exm9_4_output.PNG |