Tuesday, March 22, 2016

Kasus 4.7

Assalamuallaikum wr. wb.

Program mencari nilai dari angka yang dipangkatkan.

1. RAPTOR


2. C++

#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 x,hasil;
   int i, 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;
}

Dan hasil compilenya adalah :



Semoga bermanfaat !!!

Wassalamuallaiku wr. wb.

0 comments :

Post a Comment