Kasus 4.7

Permasalahan :
Menghitung nilai dari dengan x bilangan real dan y bilangan bulat.


C++ :
#include <iostream>
#include <conio.h>
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;
   getch();
}

Output :

Raptor :


Share this

Related Posts

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
:-?
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
$-)
(y)
(f)
x-)
(k)
(h)
cheer