Tampilkan postingan dengan label Algoritma. Tampilkan semua postingan
Tampilkan postingan dengan label Algoritma. Tampilkan semua postingan

Kamis, 08 Desember 2011

SOAL FUNCTION(1)


Soal  1 :
Ada 2 parameter (x,y), hitung angka ganjil dari Ganjil (X,Y), contoh :
Ganjil(2,10)         -> hasil : 3 5 7 9
Ganjil(10,5)         -> hasil : ERROR
Buatlah Flowchart Algoritma dan Program VBScript HTML 

FLOWCHART

PROGRAM VBScript HTML
<html>
    <head>
        <script language="VBS">
            function ganjil(a,b)
                dim hitung
                hitung = ""
                for p=a to b
                    if p mod 2 = 1 then
                        hitung = hitung & " " & p
                    end if
                next

                ganjil = hitung
            end function
        </script>   
    </head>
    <body>
        <script language="VBS">
            x=cint(inputbox("masukkan X"))
            y=cint(inputbox("masukkan Y"))
            If x<y then
                hasil = ganjil(x,y)               
            else
                hasil = "ERROR"
            end if
           
            document.write hasil

        </script>
    </body>
</html> 



Soal 2 :
Ada 4 parameter (a,b,c,d), hitung pekalian dari Perkalian(a,b,c,d) = Carimax(a,b,c,d) * Carimin(a,b,c,d), contoh :
Carimax(4,5,6,7)               -> hasil : 7
Carimin(4,5,6,7)                -> hasil : 4
Perkalian(4,5,6,7)              -> hasil : 7 * 4 = 28
Buatlah Flowchart Algoritma dan Program VBScript HTML

FLOWCHART


PROGRAM VBScript HTML

<html>
    <head>
        <script language="VBS">
            function carimax(h,i,j,k)
                dim hitung
                dim ab
                dim abc
                dim abcd
               
                if h>i then
                    ab = h
                else
                    ab = i
                end if
               
                if ab>j then
                    abc = ab
                else
                    abc = j
                end if
               
                if abc>k then
                    abcd = abc
                else
                    abcd = k
                end if
               
                hitung = abcd
                carimax = hitung
            end function
        </script>
        <script language="VBS">
            function carimin(h,i,j,k)
                dim hitung
                dim ab
                dim abc
                dim abcd
               
                if h<i then
                    ab = h
                else
                    ab = i
                end if
               
                if ab<j then
                    abc = ab
                else
                    abc = j
                end if
               
                if abc<k then
                    abcd = abc
                else
                    abcd = k
                end if
               
                hitung = abcd
                carimin = hitung
            end function
        </script>   
        <script language="VBS">
            function perkalian(p,q,r,s)
                dim hitung
               
                hitung = carimax(p,q,r,s)*carimin(p,q,r,s)
               
                perkalian = hitung
            end function
        </script>       
    </head>
    <body>
        <script language="VBS">
            a=cint(inputbox("masukkan A"))
            b=cint(inputbox("masukkan B"))
            c=cint(inputbox("masukkan C"))
            d=cint(inputbox("masukkan D"))
           
            nilmin = carimin(a,b,c,d)
            nilmax = carimax(a,b,c,d)
            hasil = perkalian(a,b,c,d)               
           
            document.write "Nilai Min = " & nilmin & "</br>"
            document.write "Nilai Max = " & nilmax & "</br>"
            document.write "Hasil perkalian = " & hasil

        </script>
    </body>
</html>



 




Selasa, 06 Desember 2011

MAIN PROGRAM & SUBPROGRAM (FUNCTION & PROCEDURE)

MAIN PROGRAM adalah kumpulan perintah yang merupakan bagian utama program, karena bagian ini yg pertama kali dikerjakan saat program dijalankan.

SUBPROGRAM adalah kumpulan perintah yg independent (berdiri sendiri) dan dijalankan saat dipanggil oleh main program atau subprogram lain.

Ada 2 jenis Subprogram yaitu FUNCTION dan PROCEDURE.

FUNCTION adalah Subprogram yg nama functionnya merupakan variable penampung hasil (return value) dari function yg bersangkutan.

PROCEDURE adalah subprogram yg dijalankan dengan statement CALL.

CONTOH :

Hitung  X = -> N diinputkan

FLOWCHART


PROGRAM VBSCRIPT HTML

<html>
    <head>
        <script language="VBS">//SUBPROGRAM
            function pangkat(parameter1)
                dim hasil

                hasil = 1

                for p=1 to 3
                    hasil  = hasil*parameter1
                next

                pangkat = hasil
            end function
        </script>
        <script language="VBS">//SUBPROGRAM
            function faktorial(parameter2)
                dim hasil
               
                hasil = 1
                for l=1 to parameter2
                    hasil = hasil*l
                next

                faktorial = hasil
            end function
        </script>
    </head>
    <body>//MAIN PROGRAM
        <script language="VBS">

            n=inputbox("masukkan N")
            for i=1 to N
                pembilang = pangkat(i)
                penyebut = faktorial(i)
                x=x+(pembilang/penyebut)
            next

            document.write(x)

        </script>
    </body>
</html> 



Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | GreenGeeks Review