diff options
Diffstat (limited to '37/CH1/EX1.5/Solved5.sci')
-rwxr-xr-x | 37/CH1/EX1.5/Solved5.sci | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/37/CH1/EX1.5/Solved5.sci b/37/CH1/EX1.5/Solved5.sci new file mode 100755 index 000000000..259e2b86c --- /dev/null +++ b/37/CH1/EX1.5/Solved5.sci @@ -0,0 +1,24 @@ +//Solved Example 7:
+//Reducing The Given Rational Number
+funcprot(0)
+function[y]=reduce(nm,dn)
+rational1=struct('numerator',nm,'denominator',dn)
+y=0
+if(rational1.numerator>rational1.denominator)
+ a=rational1.numerator;
+ b=rational1.denominator;
+else
+ a=rational1.denominator;
+ b=rational1.numerator;
+end
+while(b~=0)
+ rem=modulo(a,b);
+ a=b;
+ b=rem;
+end
+y=struct('numerator',nm/a,'denominator',dn/a);
+disp(y);
+endfunction
+nm=22;
+dn=44;
+y=reduce(nm,dn)
\ No newline at end of file |