I finally figured out how to use Codeform. I had to use the online version though. Here is my code for the Fibonacci Number Program.
I used this website to figure out what a Fibonacci Number was:
http://www.jimloy.com/algebra/fibo.htm
It works all the way up to Line 47 which gives me a negative value:
Picture of Output
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n; /* Number of Fibonnacci Numbers to Find (Inputed by User) */
int index = 1; /* Index of Fibonnaci Number (Starts with 1) */
long int fib_num = 0; /* Fibonacci Number */
long int num1 = 1; /* Represents 1 Fib# before Last Fib# */
long int num2 = 1; /* Reprsents Last Fib# */
/* Prompts user for n, and reads input */
printf( "Please enter the amount of Fibonacci\n"
"numbers to find: ");
scanf( "%ld", &n );
/* Executed until Fib#'s Found == Fib#'s Wanted by User */
while ( index <= n )
{
if ( index <= 2 )
{
printf( "\nFibonacci Number #%d = %ld", index, num2 );
}
else
{
fib_num = num1 + num2;
num1 = num2;
num2 = fib_num;
printf( "\nFibonacci Number #%d = %ld", index, num2);
}
index++;
}
return 0;
}
I completely ignored pointers, and I am sure there is probably a better algorithm.
Let the corrections/learning begin.
(I don't see a use for pointers even though I am sure there is one, but in this situation it seems that the variables are used until the program terminates so i can't see how you could free the memory much sooner than it already is.)