diff options
Diffstat (limited to '662/CH8/EX8.2/Example8_2.sci')
-rwxr-xr-x | 662/CH8/EX8.2/Example8_2.sci | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/662/CH8/EX8.2/Example8_2.sci b/662/CH8/EX8.2/Example8_2.sci new file mode 100755 index 000000000..5741c374d --- /dev/null +++ b/662/CH8/EX8.2/Example8_2.sci @@ -0,0 +1,23 @@ +//Programming Example 8.2
+// calculate the factorial of an integer quantity
+
+funcprot(0)
+function[] = mainfact()
+ //read in the integer quantity
+ printf("\nn=")
+ n=scanf("%d")
+ //calculate and display the factorial
+ printf("\nn! = %d",Factorial(n))
+endfunction
+
+function[prod] = Factorial(n) //calculate the factorial
+ prod=1
+ if n > 1 then
+ for i = 2 : n
+ prod = prod * i
+ end
+ end
+ return(prod);
+endfunction
+// calling routine
+mainfact()
\ No newline at end of file |