Hi reiko,
In addition to the aforementioned missing closing brace (or curly bracket if you prefer), I notice that there is a semicolon after the first IF statement. This has the effect of saying, "if x is equal to 0 or 1, do nothing". The following RETURN statement is unconditional because it is not in the scope of the IF.
Furthermore, if you remove THAT semicolon, the semicolon after the RETURN has the effect of pushing the ELSE out of the scope of the IF. Perhaps you meant something like this:
Code: Select all
if (x == 0 || x == 1)
{return x;}
else
{etc;
etc;
etc;};
Note that semicolons INSIDE of braces won't end the scope of the IF. (My positioning of those is a bit unconventional but you get the point.)
You use scanf to input the value of A, then printf to display the value of A. Do you mean to display the value of B instead?
Also, this program will obviously fail if you enter an A of more than 9. Your attempt to access the A'th entry of the array will use an out-of-range subscript, and as my old IBM manuals like to say, "results are unpredictable". C has no protection against out-of-range subscripts, and it is expected the programmer will take great pains to defend against them.
Since you don't really need to save ALL the Fibonacci numbers, I would have done it something like this:
Code: Select all
p = 0;
q = 1;
<begin loop here>
r = p + q;
<exit loop when done>
p = q;
q = r;
<repeat loop>
This code only saves the last two Fibonacci numbers, and by running through the loop an arbitrary number of times, you can get to any number you wanted (until the numbers get so big they won't fit into an INT anymore).
Good luck learning C programming!
Caitlin