#include <iostream.h>
#include <conio.h>
int fibonacci (int n)
{ if ((n == 1) || (n == 2)) return(1);
else return(fibonacci(n-1) + fibonacci(n-2));
}
int main() {
int i, n;
cout << "Sampai suku ke : "; cin >> n;
for (i = 1; i <= n; i++) cout << fibonacci(i) << " ";
getch();
return 0;
}
Hasil:
2 Responses so far