I wrote this code for the first 25 terms of the fibonacci sequence beginning with 1. It works fine, but I need it as a while loop and nothing I tried works. How do I change it over to a while loop?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
int main ()
{
int j=1, k=1, sum;
for (int i=0; i<25; i++)
{
cout << j << " ";
sum=j+k;
j=k;
k=sum;
}
return 0;
}