D is a systems programming language with C-like syntax, combining the power of C with modern language features such as garbage collection and strong type safety.

How to test

Prerequisites: GDC or LDC D compiler

  • Ubuntu/Debian: sudo apt install gdc
  • macOS: brew install ldc
gdc fibonacci.d -o fibonacci && ./fibonacci

Or with LDC:

ldc2 fibonacci.d -of=fibonacci && ./fibonacci

Expected output:

0
1
1
2
3
5
8
13
21
34

Source Code

import std.stdio;

void main() {
    int a = 0, b = 1, c;
    foreach (_; 0 .. 10) {
        writeln(a);
        c = a + b;
        a = b;
        b = c;
    }
}

Local Testing Screenshot Image