Kasus 5.6


Buatlah fungsi yang menghitung suku ke-n dari deret Fibonacci dengan menggunakan cara rekursif.



INTERAKTIF

#include <iostream>
#include <string>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
void balik(char *s)
{    int i;
     for (i=strlen(s)-1; i>=0; i--)
         cout << s[i];
}

main(){
     char *kata = "Algoritma";
     balik(kata);
     return 0;  
}

 

 

 

REKURSIF

#include <iostream>
#include <string>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
void balik(char *s)
{
     if (*s != '\0') {
         balik(&s[1]);
         cout << s[0];
     }
}
main() {
     char *kata = "Algoritma";
     balik(kata);
     return 0;  
}

 
Previous
Next Post »
Copyright © 2015 Bettong'rs All Right Reserved
Created by Arlina Design Powered by Blogger