summaryrefslogtreecommitdiff
path: root/243/CH4/EX4.2/4_02.sce
blob: 112a25fbf84bedc9b4438a91d0e733608bf71709 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)