• Posted by : deari q Senin, 31 Maret 2014





    Algoritma

    Function pangkat (a : real, n : integer ) => real
    { menghitung a^n }

    Deklarasi
    i : integer
    hasil : real

    Deskripsi
    hasil <= 1
    For i <= 1 to n do
                    hasil <= hasil *a
    end
    return hasil


    program C++


    #include <cstdlib>
    #include <iostream>

    using namespace std;
    int pangkat(float a,int n){
        int i;
        float hasil;
        hasil=1;
                for(i=1; i<=n; i++)
                hasil = hasil * a;
                return (hasil);
        }

    int main(int argc, char *argv[])
    {
        int a,n;
        cout<<"masukan bilangan : ";
        cin>>a;
        cout<<"masukan pangkat  : ";
        cin>>n;
        cout<<a<<" ^ "<<n<<" = "<<pangkat(a,n)<<endl;
        system("pause");
        return 0;
    }

    Leave a Reply

    Subscribe to Posts | Subscribe to Comments

  • - Copyright © 2013 Kampus - To Aru Kagaku no Railgun - Powered by Blogger - Designed by Johanes Djogan -