C++ PROGRAM PANGKAT (REKURSIF)
C++ PROGRAM PANGKAT (REKURSIF)
#include <iostream>
#include <cstdlib>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int pangkat(int a, int N ){
if (N==0){
return (1);
}
else{
return (a*pangkat (a, N-1));
}
}
int main(int argc, char *argv[]) {
int b, x, hasil_pangkat;
cout<<"Masukkan bilangan yang akan dipangkatkan : ";
cin>>b;
cout<<"\nMasukkan jumlah pangkat : ";
cin>>x;
system("cls");
cout<<"=============================================\n";
cout<<"| PROGRAM PANGKAT (REKURSIF) |\n";
cout<<"| SRI WAHYUNI |\n";
cout<<"| 1400018214 |\n";
cout<<"| <06 JUNI 2015> |\n";
cout<<"=============================================\n\n";
hasil_pangkat = pangkat(b, x);
cout<<"b = "<<b<<endl;
cout<<"x = "<<x<<endl<<endl;
cout<<"b^x = "<<b<<"^"<<x<<endl;
cout<<" = "<<hasil_pangkat;
return 0;
}
HASIL COMPILE :
#include <iostream>
#include <cstdlib>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int pangkat(int a, int N ){
if (N==0){
return (1);
}
else{
return (a*pangkat (a, N-1));
}
}
int main(int argc, char *argv[]) {
int b, x, hasil_pangkat;
cout<<"Masukkan bilangan yang akan dipangkatkan : ";
cin>>b;
cout<<"\nMasukkan jumlah pangkat : ";
cin>>x;
system("cls");
cout<<"=============================================\n";
cout<<"| PROGRAM PANGKAT (REKURSIF) |\n";
cout<<"| SRI WAHYUNI |\n";
cout<<"| 1400018214 |\n";
cout<<"| <06 JUNI 2015> |\n";
cout<<"=============================================\n\n";
hasil_pangkat = pangkat(b, x);
cout<<"b = "<<b<<endl;
cout<<"x = "<<x<<endl<<endl;
cout<<"b^x = "<<b<<"^"<<x<<endl;
cout<<" = "<<hasil_pangkat;
return 0;
}
HASIL COMPILE :
![](https://lh4.googleusercontent.com/-sBo84x7G4v0/VZLEgaY_kuI/AAAAAAAABgg/eGNgKWUAR3E/w624-h398-rw-no/c%252B%252B%2BPangkat%2BRekursif.png)
Komentar
Posting Komentar
-Berkomentarlah yang baik dan rapi.
-Menggunakan link aktif akan dihapus.