Skip to Content

Solution to hw00b

#include <cstdlib>
#include <iostream>
 
using namespace std;
 
int main(int argc, char *argv[])
{
 
    // read input from keyboard and store in n
    int n;             
    scanf("%d",&n);
 
    int curr; // current fibonacci number
    int next; // the next fibonacci number
 
    // compute n-th fibo number
    curr = 0;            
    next = 1;
    for (int i = 0;i < n;i++) {
        int tmp = next + curr;
        curr = next;
        next = tmp;
    }
 
    //display output
    printf("%d\n",curr);
 
    return EXIT_SUCCESS;
}

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Allowed HTML tags: <pre> <span> <div> <p> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h1> <h2> <h3> <h4> <hr> <div> <img> <blockquote> <pre> <br> <table> <tr> <td> <th> <thead> <tbody> <object> <param>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • LaTex commands embedded in text will be interpreted and rendered. Additional information can be found at DruTex Documentation Pages
    • Provides different environments to create rendered images (especially maths).
    • Line and paragraphs break automatically.
    • Assists automatic numbering of tex, equation, and equations environments.
    • Images can be added to this post.
    • Adds typographic refinements.

    More information about formatting options

    CAPTCHA
    This question is for testing whether you are a human visitor and to prevent automated spam submissions.