TUGAS ANALISA 4.7


#include <iostream>
#include <string>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std; 
int main(int argc, char** argv) {
float hasil;
int i;
float x;
int y;
hasil = 1;
cout << "Masukkan angka yang ingin dipangkatkan = ";
cin >> x;
cout << "Masukkan pangkat = ";
cin >> y;
cout << endl;
if (y>=0){
    i =1;
    while (!(i>y)){
        hasil =hasil*x;
        i =i+1;
    }
}
else{
    i =0;
    while (!(i<=y)){
    hasil =hasil*(1/x);
        i =i-1;
    }
}
cout << "=> " << x << " pangkat " << y << " adalah " << hasil << endl;
return 0;
}

Program raptornya


Comments