From 69cda5b1a5a0ba324fa6f98704c2f5567d1fee1e Mon Sep 17 00:00:00 2001 From: Arif Dwi Nugroho Date: Thu, 7 Oct 2021 17:13:11 +0700 Subject: [PATCH 1/2] Create pow_calculate.cpp calculate the power of number --- C++/pow_calculate.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 C++/pow_calculate.cpp diff --git a/C++/pow_calculate.cpp b/C++/pow_calculate.cpp new file mode 100644 index 0000000..e695611 --- /dev/null +++ b/C++/pow_calculate.cpp @@ -0,0 +1,31 @@ +#include + +using namespace std; + +int main(){ + + int x,y,i, hasil; + + cout << "Masukkan angka : "; + cin >> x; + cout << "Masukkan pangkat : "; + cin >> y; + + + if(y > 0){ + i = 1; + while(!(i > y)){ + hasil = hasil*x; + i = i + 1; + } + cout << "hasil = " << hasil << endl; + }else if(y == 0){ + hasil = 0; + cout << "hasil = " << hasil << endl; + } + + + + + return 0; +} From 74613f8c0543e036d2b7eeb2a04e9c81c7c31f28 Mon Sep 17 00:00:00 2001 From: Arif Dwi Nugroho Date: Thu, 7 Oct 2021 17:18:36 +0700 Subject: [PATCH 2/2] Create loop_with_class.cpp --- C++/loop_with_class.cpp | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 C++/loop_with_class.cpp diff --git a/C++/loop_with_class.cpp b/C++/loop_with_class.cpp new file mode 100644 index 0000000..24dd60d --- /dev/null +++ b/C++/loop_with_class.cpp @@ -0,0 +1,54 @@ +#include +#include + +using namespace std; + +class perulangan{ + public: + perulangan() { n = 4; } + void ulang_while(int n); + void ulang_for(int); + int ulang_rekursif(int); + private: + int n; +}; + +void perulangan::ulang_for(int n) { + for (int i = 1; i <=n; i++){ + cout << i << " "; + getch(); + } +} + +void perulangan::ulang_while(int n) { + int i = 4; + while (i >= n) { + cout << i << " "; + i--; + getch(); + } +} + +int perulangan::ulang_rekursif(int n){ + if(n == 4){ + getch(); + cout << n; + return 4; + }else{ + getch(); + cout << n << " "; + return ulang_rekursif(n+1); + } +} + +int main() { + perulangan X; + cout << "Menggunakan cara iteratif_for\n"; + X.ulang_for(4); + cout << "\nMenggunakan cara iteratif_while\n"; + X.ulang_for(4); + cout << "\nMenggunakan cara rekursif\n"; + X.ulang_rekursif(1); + + return 0; +}