Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // sequence is 0, 1, 1, 2, 3, 5, 8, 13, ...
- /*
- int main() {
- int number;
- char contin = 'Y';
- while(toupper(contin) == 'Y') {
- cout << "Enter a number: ";
- cin >> number;
- cout << endl << "The prime number is: " << FindPrime(number) << endl;
- cout << endl << "Would you like to continue? (Y/N): ";
- cin >> contin;
- }
- }
- */
- int fib (int i) {
- int pred, result, temp;
- pred = 1;
- result = 0;
- while (i > 0) {
- temp = pred + result;
- result = pred;
- pred = temp;
- i = i-1;
- }
- return(result);
- }
- int main () {
- char contin = 'Y';
- while(toupper(contin) == 'Y')
- int n;
- cout << "Enter a natural number: ";
- cin >> n;
- while (n < 0) {
- cout << "Please re-enter: ";
- cin >> n;
- }
- cout << "fib(" << n << ") = " << fib(n) << endl;
- return(0);
- }
Add Comment
Please, Sign In to add comment