Jumat, 15 April 2011

.ITERATIVE dan REKURSIVE (tugas kelompok)

New Team

  1. Desmala Dewi          (10018061)
  2. Dian Seli Anggraini (10018084)
  3. Sit Eka Chotimah     (10018081)
  4. Tutik Lestari             (10018070)

A.ITERATIVE TO REKURSIVE CONVERSION
    
    Iterative Step:
       for(int i=0;i<5;i++)
       cout<<“mencoba rekursi\n”;
    Rekursive Step:
      void coba(int i)
      {if(i==5)
     {}
     else
     cout<<“mencoba rekursi\n”;coba i+1;
     }
     main()
    {int i=0;
    coba(i);
    }

B.REKURSIVE TO ITERATIVE

   Rekursive Step:
   void coba(int i)
   {if(i==5)
   {}
   else
   cout<<“mencoba rekursi\n”;coba i+1;
   }
   main()
   {
   int i=0;
   coba(i);
   }
   Iterative Step:
   for(int i=0;i<5;i++)
   cout<<“mencoba rekursi\n”;
 


C. ANALISIS

For example, the function is called with value i = 0 so for the first we must check is i = 5 {if(i==5) or not, and if its have a same value its will be out.
  In reality, i is not same with 0 so, please add i with 1. And the condition now become i = 2.
In next line, we show the value of i. Next, called rekursive function with value i = 2.
That steps is repeating until rekursive function calling with value i = 5. 
For now, the if condition is true and that make the function out (return) and continue the command after calling rekursive function with i = 5. Then print out value i.
After print out value i then rekursive function will be out again, and go a head to the command after calling rekursive function where the value before is i = 4. And thats repeating until the value i = 0, thats the first calling rekursive function.

This is the calling rekursif function ilustrated in Indonesia: 
Langkah ke :
1. i = 4 ; mencoba rekursi
2. i = 3 ; mencoba rekursi
3. i = 2 ; mencoba rekursi
4. i = 1 ; mencoba rekursi
5.i  = 0 ; mencoba rekursi
Jika di panggil i=5 akan keluar,sebaliknya dengan operasi rekursif ke iteratif
 

Tidak ada komentar:

Posting Komentar