Fibonacci Sequence in C
Level 3119 keystrokes
Generates and prints the first 7 numbers of the Fibonacci sequence.
C code
// a and b hold the last two numbers; c will hold the next one1int a = 0, b = 1, c;// The first two numbers, 0 and 1, are printed directly2printf("%d %d ", a, b);// 5 more numbers, 7 in total3for (int i = 0; i < 5; i++) { // Next = sum of the last two, then shift: a takes b, b takes c (order matters)4 c = a + b; a = b; b = c; // Print 1, 2, 3, 5, 85 printf("%d ", c);6}Output
0 1 1 2 3 5 8
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
;× 8=× 6,× 5"× 4(× 3)× 3%× 3+× 3{× 1}× 1