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

...ents\Visual Studio\c++\NewProject1\NewProject1\Main.

cpp 1
1 #include <iostream>
2
3 void fibonacci(int n);
4
5 int main()
6 {
7 int n;
8 std::cout << "Banyak n Fibonacci : ";
9 std::cin >> n;
10 std::cout << std::endl;
11 fibonacci(n);
12 system("pause");
13 }
14
15 void fibonacci(int n)
16 {
17 int a = 0;
18 int b = 1;
19 int c = 0;
20 int count = 1;
21 std::cout << "Bilangan Fibonacci : " << std::endl;
22 std::cout << b << " ";
23 for (int i = 0; i < n; i++) {
24 c = b + a;
25 count = count + c;
26 std::cout << c << " ";
27 a = b;
28 b = c;
29 }
30 std::cout << std::endl << "Hasil Penjumlahan dari bilangan fibonaci tsb : "
<< count << std::endl;
31 }

You might also like