Vrydag 04 April 2014

Program Brute Force Pangkat

Program

#include <cstdlib>
#include <iostream>

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

int main(int argc, char *argv[])
{                   
    int a,n;
    cout<<"Masukkan angka :";cin>>a;
    cout<<endl;
    cout<<"Masukkan pangkat :";cin>>n;
    cout<<endl;
    cout<<"Hasil perpangkatan = "<<pangkat(a,n);
    cout<<"\n";

    cout<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}



Running

Geen opmerkings nie:

Plaas 'n opmerking