Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Nama: Lalu Watdian Suryawijaya

NIM: 22181196
Kelas: B
Tugas 2
1. Cn = 2 Cn-1 + 1, Jika C0 = 1
A. Soruce Code
#include <iostream>
using namespace std;
int C (int n){ if (n==0) { return 1;
}
else {
return 2*C(n-1)+1;
} } int main (){ int x, y;
cout<<"Cari Nilai dari Fungsi Rekruatif"<<endl;
cout<<"Masukkan Bilangan n = "; cin>>x;
for(y=0;y<=x;y++){
cout<<"Hasil Perhitungan "<<y<<" : "<<C(y)<<endl;
}
}

B. Hasil Tampilan

C. Analisa
Fase Awal
C4 = 2 C3 + 1
C3 = 2 C2 + 1
C2 = 2 C1 + 1
C1 = 2 C0 + 1
C0 = 1 Fase Terminated
Fase Balik
C0 = 1
C1 = 2 * 1 + 1 = 3
C2 = 2 * 3 + 1 = 7
C3 = 2 * 7 + 1 = 15
C4 = 2 * 15 + 1 = 31
2. an = 2n an-1, Jika a0 = 1
A. Source Code
#include <iostream>
using namespace std;
int C (int n){ if (n==0) { return 1;
} else {
return 2*n*C(n-1);
} } int main (){ int x, y;
cout<<"Cari Nilai Dari Fungsi Rekruaif"<<endl;
cout<<"Masukkan Bilangan n = "; cin>>x;
for(y=0;y<=x;y++){
cout<<"Hasil Perhitungan "<<y<<" : "<<C(y)<<endl;
}
}

B. Hasil Tampilan

C. Analisa
Fase Awal
a4 = 2 * 4 * a(3)
a3 = 2 * 3 * a(2)
a2 = 2 * 2 * a(1)
a1 = 2 * 1 * a(0)
a0 = 1 Fase Terminated
Fase Balik
a0 = 1
a1=2 * 1 * 1 = 2
a2=2 * 2 * 2 = 8
a3=2 * 3 * 8 = 48
a4=2 * 4 * 48 = 384
3. Sn = Sn-1 + n-1, Jika S1 = 0
A. Source Code
#include <iostream>
using namespace std;
int C (int n){ if (n<=1) { return 0;
} else {
return C(n-1)+(n-1);
} } int main (){ int x, y;
cout<<"Cari Nilai Dari Fungsi Rekruaif"<<endl;
cout<<"Masukkan Bilangan n = "; cin>>x;
for(y=0;y<=x;y++){
cout<<"Hasil Perhitungan "<<y<<" : "<<C(y)<<endl;
}
}

B. Hasil Tampilan

C. Analisa
Fase Awal
S4 = S3 + 3
S3 = S2 + 2
S2 = S1 + 1
S1 = 0 Fase Terminated
Fase Balik
S1 = 0
S2 = 0 + 1 = 1
S3 = 1 + 2 = 3
S4 = 3 + 3 = 6
4. Sn = Sn-1 + 2, Jika S0 = 0
A. Source Code
#include <iostream>
using namespace std;
int C (int n){ if (n==0) { return 0;
} else {
return C(n-1)+2;
} } int main (){ int x, y;
cout<<"Cari Nilai Dari Fungsi Rekruaif"<<endl;
cout<<"Masukkan Bilangan n = "; cin>>x;
for(y=0;y<=x;y++){
cout<<"Hasil Perhitungan "<<y<<" : "<<C(y)<<endl;
}
}

B. Hasil Tampilan

C. Analisa
Fase Awal
S4 = S3 + 2
S3 = S2 + 2
S2 = S1 + 2
S1 = S0 + 2
S0 = 0 Fase Terminated
Fase Balik
S0 = 0
S1 = 0 + 2 = 2
S2 = 2 + 2 = 4
S3 = 4 + 2 = 6
S4 = 6 + 2 = 8
5. an = an-1 + 4, Jika a0 = 0
A. Source Code
#include <iostream>
using namespace std;
int C (int n){ if (n==0) { return 0;
} else {
return C(n-1)+4;
} } int main (){ int x, y;
cout<<"Cari Nilai Dari Fungsi Rekruaif"<<endl;
cout<<"Masukkan Bilangan n = "; cin>>x;
for(y=0;y<=x;y++){
cout<<"Hasil Perhitungan "<<y<<" : "<<C(y)<<endl;
}
}

B. Hasil Tampilan

C. Analisa
Fase Awal
S4 = S3 + 4
S3 = S2 + 4
S2 = S1 + 4
S1 = S0 + 4
S0 = 0 Fase Terminated
Fase Balik
S0 = 0
S1 = 0 + 4 = 4
S2 = 4 + 4 = 8
S3 = 8 + 4 = 12
S4 = 12 + 4 = 16
6. Tabel
A. Tabel No 1
Fase Awal Fase Terminated Fase Balik
C4 = 2 C3 + 1 C0 = 1 C0 = 1
C3 = 2 C2 + 1 C1 = 2 * 1 + 1 = 3
C2 = 2 C1 + 1 C2 = 2 * 3 + 1 = 7
C1 = 2 C0 + 1 C3 = 2 * 7 + 1 = 15
C0 = 1 C4 = 2 * 15 + 1 = 31
B. Tabel No 2
Fase Awal Fase Terminated Fase Balik
a4 = 2 * 4 * a(3) a0 = 1 a0 = 1
a3 = 2 * 3 * a(2) a1 = 2 * 1 * 1 = 2
a2 = 2 * 2 * a(1) a2 = 2 * 2 * 2 = 8
a1 = 2 * 1 * a(0) a3 = 2 * 3 * 8 = 48

a0 = 1 a4 = 2 * 4 * 48 =
384
C. Tabel No 3
Fase Awal Fase Terminated Fase Balik
S4 = S3 + 3 S1 = 0 S1 = 0
S3 = S2 + 2 S2 = 0 + 1 = 1
S2 = S1 + 1 S3 = 1 + 2 = 3
S1 = 0 S4 = 3 + = 6
D. Tabel No 4
Fase Awal Fase Terminated Fase Balik
S4 = S3 + 2 S0 = 0 S0 = 0
S3 = S2 + 2 S1 = 0 + 2 = 2
S2 = S1 + 2 S2 = 2 + 2 = 4
S1 = S0 + 2 S3 = 4 + 2 = 6
S0 = 0 S4 = 6 + 2 = 8
E. Tabel No 5
Fase Awal Fase Terminated Fase Balik
S4 = S3 + 4 S0 = 0 S0 = 0
S3 = S2 + 4 S1 = 0 + 4 = 4
S2 = S1 + 4 S2 = 4 + 4 = 8
S1 = S0 + 4 S3 = 8 + 4 = 12
S0 = 0 S4 = 12 + 4 = 16
7.

You might also like