Selamat Datang di Blog Sederhana Saya

This is default featured post 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Kamis, 03 November 2011

praktikum sdata postest 1

Buatlah program dalam bentuk class yang mempunyai bentuk rekursif untuk menghitung dengan rumus fungsi :

permutasi
kombinasi

Gunakan fungsi rekursif faktorial!

Buatlah program untuk menampilkan deret fibonacci dan jumlah nilai fibonacci dalam bentuk rekursif, buat dengan class!

Jawab :

1. Permutasi, kombinasi
#include
#include

using namespace std;
class soal1{
public:
soal1();
int faktorial(int);
int kombinasi(int,int);
int permutasi(int,int);
private:
int n,r;
};
soal1::soal1(){
cout<<"nilai n:";cin>>n;
cout<<"nilai r:";cin>>r;

cout<<"Kombinasi : "<
#include

using namespace std;
class soal2{
public:
soal2();
int fibonacci(int);
int deret();
private:
int f;

};
soal2::soal2(){
cout<<"masukkan batas suku deret :"; cin>>f;

}
int soal2::fibonacci(int n){
if((n==1)||(n==2)){return 1;}
else {
return (fibonacci(n-1)+fibonacci(n-2));

}
}
int soal2::deret(){
for(int i=1;i<=f;i++){
cout< }
cout<
}
int main(int argc, char** argv) {
soal2 a;
a.deret();

return 0;
}

praktikum 1 sdata

1. Apa perbedaan fungsi Rekursif dengan Fungsi Iteratif?

2. Buat algoritma untuk menghitung deret S = 2+4+6+8+10+…+2n menggunakan function rekursi

3. Buatlah fungsi program untuk menghitung faktorial dengan menggunakan fungsi rekursif dan fungsi biasa(iteratif)

Jawab :
1 1. Perbedaan :
2 - Iteratif menggunakan FOR, WHILE, DO-WHILE sedangkan rekursif hanya menggunakan IF.
3 - Iteratif dapat berjalan pada program yang terdiri dari prosedur (Tidak terdapat fungsi) sedangkan rekursif merupakan fungsi.
1 2. Function S(input n:integer)  integer
2 Deskripsi
3 If (n==1) Then
4 return (2)
5 Else
6 return (2*n + S(n-1))
7 Endif
view source
print?
01 3. Faktorial rekursif
02 int Faktorial(int n)
03 {
04 if ((n == 0) || (n == 1 ))
05 return (1);
06 else
07 return (n * Faktorial(n-1));
08 }
09
10 Faktorial iteratif
11 int fact_it (int n)
12 {
13 int temp;
14 temp = 1;
15 if (n < 0)
16 return 0;
17 else if (n == 0)
18 return 1;
19 else if (n == 1)
20 return 1;
21 Else
22 for (int i=2; i<=n; ++i)
23 temp = temp * i;
24 return (temp);
25 }

Praktikum APBO diagram aktiviti (bisnis pendaftaran praktikum di UAD)