diff options
Diffstat (limited to '243/CH4/EX4.2/4_02.sce')
-rwxr-xr-x | 243/CH4/EX4.2/4_02.sce | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/243/CH4/EX4.2/4_02.sce b/243/CH4/EX4.2/4_02.sce new file mode 100755 index 000000000..112a25fbf --- /dev/null +++ b/243/CH4/EX4.2/4_02.sce @@ -0,0 +1,43 @@ +//Example No. 4_02
+//Accuracy of numbers
+//Pg No. 63
+clear ;close ;clc ;
+
+function n = sd(x)
+ nd = strindex(x,'.') //position of point
+ num = str2code(x)
+ if isempty(nd) & num(length(x)) == 0 then
+ mprintf('Accuracy is not specified\n')
+ n = 0 ;
+ else
+ if num(1)>= 1 & isempty(nd) then
+ n = length(x)
+ elseif num(1) >= 1 & ~isempty(nd) then
+ n = length(x) - 1
+ else
+ for i = 1:length(x)
+ if num(i) >= 1 & num(i) <= 9 then
+ break
+ end
+ end
+ n = length(x)- i + 1
+ end
+ end
+endfunction
+a = '95.763'
+na = sd(a)
+mprintf('%s has %i significant digits\n',a,na)
+b = '0.008472'
+nb = sd(b)
+mprintf('%s has %i significant digits.The leading or higher order zeros are only place holders\n',b,nb)
+c = '0.0456000'
+nc = sd(c)
+mprintf('%s has %i significant digits\n',c,nc)
+d = '36'
+nd = sd(d)
+mprintf('%s has %i significant digits\n',d,nd)
+e = '3600'
+sd(e)
+f = '3600.00'
+nf = sd(f)
+mprintf('%s has %i significant digits\n',f,nf)
\ No newline at end of file |