Răspuns:
#include <iostream>
#include <fstream>
using namespace std;
ofstream f("fibonacci.out");
int main()
{
int n;
cin >> n;
int a=1, b=1;
if (n==1) {
f << a;
}
else {
if (n==2) {
f << a << " " << b;
}
else {
f << a << " " << b;
int c;
for (int i=3; i<=n; i++) {
c=a+b;
f << " " << c;
a=b; b=c;
}
}
}
return 0;
}
Explicație:
Succese!