Tuklasin ang mundo ng kaalaman at mga sagot mula sa komunidad sa IDNStudy.com. Tuklasin ang malalim na sagot sa iyong mga tanong mula sa aming komunidad ng mga bihasang propesyonal.

Create a C++ program that accepts a user input number N and prints the first N sequence of fibonacci sequence.

Sagot :

#include <iostream>

#include <fstream>

void fib(int n){

 int a = 0, b = 1, t = 0;

 for(int i=1; i<=n; i++){

   std::cout << b << " ";

   t = b;

   b = a + b;

   a = t;

 }

}

int main(){

 int i = 1;

 std::cout << "Enter a number: ";

 std::cin >> i;

 fib(i);

 return 0;

}

View image Pvzzombs