For intro to c programming The Fibonacci number series is de
For intro to c programming!!!!
The Fibonacci number series is defined as follows:
f(0) = 0, f(1) = 1, and for i > 1, f(i) = f(i-1) + f(i-2).
The first 10 numbers from the series are 0,1,1,2,3,5,8,13,21,34. Thus, f(0)=0, f(1)=1, f(2)=1, f(3)=2, etc.
a) Write in the text box below a function called fib that returns void and that takes as parameters an array v of type int and an integer n that indicates the length of array v. This function computes each Fibonacci number f(i) and saves it to array element v[i], for 0 <= i < n.
If parameter n is negative, the function must print an error message and call exit(1).
Hint: when computing element v[i] use v[i-1] and v[i-2].
b) Write a main() function that declares an int array numbers of size N, where N is a constant equal to 100 and then calls the fib function defined above with parameters numbers and N. After that, print all elements from the numbers array to the terminal.
Ensure the code is correct, aligned, and indented properly. Use space characters to type indentation. Use meaningful variable names.
Solution
program import java.applet.Applet;
 import java.awt.*;
 public class fib extends Applet
 {
 Label numLabel, resultLabel;
 TextField num, result;
 public void init()
    {
    numLabel = new Label(\"Enter an integer and press return\");
    num = new TextField(10);
    resultLabel = new Label(\"Fibonacci value is\");
    result = new TextField(15);
    result.setEditable(false);
    add( numLabel);
    add( num);
    add (resultLabel);
    add (result);
     }
 public boolean action(Event e, Object o)
 {
    long number, fibonacciVal;
    number = Long.parseLong( num.getText());
    showStatus(\"Calculating ...\");
    fibonacciVal = fibonacci (number);
    showStatus (\"Done.\");
    result.setText (Long.toString( fibonacciVal ));
    return true;
 }
 long fibonacci (long n)
 {
    if ( n == 0 || n == 1)
        return n;
    else
        return (fibonacci(n-1) + fibonacci(n-2));
 }
 }

