Fibonacci sequence into a vector<string> for sorting.

Write a function to produce the Fibonacci sequence. Use this function to fill a vector<string>
with the first ten Fibonacci numbers. Sort the vector lexicographically and print the resulting
sequence to the screen.

I've tried this, but i need to put everything in the Vector<string> and split every number above 10 and sort it.

For any Help i would be thankfull.

Have a nice day everybody.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  int fib(int n)
{
  if(1 == n || 2 == n)
  {
      return 1;
  }
  else
  {
      return fib(n-1) + fib(n-2);
  }

}

int main (){

vector<string> fibo;
string temp[25];

for(int i=1; i<=10; i++)
        {
                temp[i]=to_string(fib(i));

                cout << fib(i) << '\t';


        }

cout << endl;

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

        cout << temp[i] << '\t';
}
cout << endl;



return 0;
}
Topic archived. No new replies allowed.