Dissecting a sample C program
#include <stdio.h> // Preprocessor directive
// C program uses this as the entry point for executation
int main( )
{
// Functions contain a number of statements
// Each variable allocated a space in memory (RAM)
// They do not have initial values
int cur, prev1 = 1, prev2 = 1, i, n;
// Fibonacci sequence length
n = 4;
if( n <= 2 ){
cur = 1;
} else {
for ( i = 3; i<=n; i++ ) {
cur = prev1 + prev2;
prev2 = prev1;
prev1 = cur;
}
}
printf("Answer is %d\n", cur);
return 0;
}