Question

c++ code that outputs the 25th number in the fibonacci sequence

c++ code that outputs the 25th number in the fibonacci sequence

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<iostream>
using namespace std;

int fib(int n){
   int a,b,c;
   if(n == 1){
      return a;
   }
   if(n == 2){
      return b;
   }
   else{
      for(a = 0,b = 1;n>2;n--){
         c = a + b;
         a = b;
         b = c;
      }
      return c;
   }
}

int main(){
   int n = 25;
   
   cout<<n<<"th fibonacci number is "<<(fib(n))<<endl;
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
c++ code that outputs the 25th number in the fibonacci sequence
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT