Kasus 4.7

Pertanyaan :
Hitunglah nilai dari dengan x bilangan real dan y bilangan bulat.

Jawaban : 

#include <iostream>
#include <string>
using namespace std;
int main(){
   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;
}



Raptor :


Share on Google Plus

About Luthfi

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment