// John Bent's CS 110 Hand-out 15 // Iterative fibbonacci solution. // // This program uses an iterative solution to return // the value of the n'th term of the fibbonacci sequence. // // Limitations - No error checking of user input. #include #include // allows use of setiosflags, setprecision void main() { long double number1 = 1, number2 = 1, swap, term; cout << "\nWhich term of fib would you like to see? "; cin >> term; while (term < 1) { // assures that term entered is positive cout << "Term must be a positive integer: "; cin >> term; } // while for (int i = 2; i < term; i++) { // keep figuring next fib until got it swap = number1; number1 += number2; cout << "\t" << i << ": " << number1 << endl; number2 = swap; } // for cout << setiosflags( ios::fixed); // don't use sci. notation cout << setprecision(0); // show 0 decimal places cout << "\tThat term is " << number1 << endl << endl; } // main