วันจันทร์ที่ 11 กันยายน พ.ศ. 2560

factorial

p=input("ตัวเลขคือ");
fact=1
for k=1:p
fact = k*fact

end
printf("ค่า %d factorialเท่ากับ%d\n",p,fact)


-->exec('C:\Users\5810110621\Documents\fac2.sce', -1)
ตัวเลขคือ4
ค่า 4 factorialเท่ากับ24

if else 2

p=input("ตัวเลข");
if(p>0)
    printf("\n positive")

elseif(p<0)
    printf("\n negative")

else
    printf("\n Zero")

end

-->exec('C:\Users\5810110621\Documents\intro2.sce', -1)
ตัวเลข20

 positive


-->exec('C:\Users\5810110621\Documents\intro2.sce', -1)
ตัวเลข-5

 negative

-->exec('C:\Users\5810110621\Documents\intro2.sce', -1)
ตัวเลข0

 Zero

if else 1

function s=signum(x)
if(x>0)
s='positive'
elseif(x<0)
s='negative'
else
s="Zero";
end
endfunction

-->signum(0)
 ans  =

 Zero

my salary 3

p=input("เงินเดือน");
n=input("จำนวนปีที่ฝาก");
i=input("ดอกเบี้ยเงิน");
for j=1:n
    f(j)=(p*12)*(1+(i/100))^j;
    U=f(j);
j=j+1;
end
printf("\เงินในปีที %dเท่ากับ.%3f\n",n,U);

-->exec('C:\Users\5810110621\Documents\sci3.sce', -1)
เงินเดือน30000
จำนวนปีที่ฝาก20
ดอกเบี้ยเงิน1.25
àงินในปีที 20เท่ากับ.461533.403415