summaryrefslogtreecommitdiff
path: root/662/DEPENDENCIES/second_file.sci
diff options
context:
space:
mode:
Diffstat (limited to '662/DEPENDENCIES/second_file.sci')
-rwxr-xr-x662/DEPENDENCIES/second_file.sci29
1 files changed, 29 insertions, 0 deletions
diff --git a/662/DEPENDENCIES/second_file.sci b/662/DEPENDENCIES/second_file.sci
new file mode 100755
index 000000000..adb2a8c77
--- /dev/null
+++ b/662/DEPENDENCIES/second_file.sci
@@ -0,0 +1,29 @@
+//Programming Example 8.12
+//calculate Fibonacci number (F=1 for i<3, and F= F1+F2 for i>=3)
+ //Second File
+
+function[f]=Fibonacci(count)
+global f1;
+global f2;
+global first;
+
+//As in static variables the initialization takes place only once
+//but static is not available in scilab
+// hence use of global variable first is made here
+// and initialized only once..
+if(first=="true") then
+ f1=1;
+ f2=1 ;
+ first="false" ;
+end
+
+
+ if(count<3) then
+ f=1
+ else
+ f=f1+f2
+ end
+ f2=f1;
+ f1=f;
+ return f;
+endfunction \ No newline at end of file