Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

D Enum

d

import std.stdio;

enum Days { sun, mon, tue, wed, thu, fri, sat };

int main(string[] args) {
   Days day;

   day = Days.mon;
   writefln("Current Day: %d", day); 
   writefln("Friday : %d", Days.fri); 
   return 0;
}

D Character Types

d

import std.stdio;

int main() {
   writeln("Length in bytes: ", char.sizeof);
   
   return 0;
}

D Floating Point Types

d

import std.stdio;

int main() { 
   writeln("Length in bytes: ", float.sizeof); 

   return 0; 
}

D Integer Types

d

import std.stdio; 
 
int main() { 
   writeln("Length in bytes: ", ulong.sizeof); 

   return 0; 
}

D Variable Declaration

d

import std.stdio; 
 
int a = 10, b = 10; 
int c;
float f;  

int main () { 
   writeln("Value of a is : ", a); 
   
   /* variable re definition: */ 
   int a, b; 
   int c; 
   float f;
   
   /* Initialization */ 
   a = 30; 
   b = 40; 
   writeln("Value of a is : ", a); 
   
   c = a + b; 
   writeln("Value of c is : ", c);  
   
   f = 70.0/3.0; 
   writeln("Value of f is : ", f); 
   return 0; 
}

D Hello World

d

import std.stdio; 
 
void main(string[] args) { 
   writeln("Hello World!"); 
}

Sub Array Printer

d

import std.stdio;
import std.string, std.math;

int main(string[] args)
{
    string[] kume;
    
    writeln("Kümenin elemalarını giriniz: \n");
    kume = readln.chomp.split(" ");
    
    int altkume = cast(int)pow(2, kume.length);
    
    for(int i = 0; i < altkume; i++)
    {
        write("{ ");
        ulong combination = i;
        for(int j = 0; combination > 0; j++)
        {
            if(combination % 2 == 1)
            {
                write(kume[j]);
                if(combination / 2 > 0)
                    write(", ");
            }
            combination /= 2;
        }
        writeln(" }");
    }
    
	return 0;
}

Testing

d

import std.stdio;

/* Hello World Program in D Programming */
void main(string[ ] args)
{
   writeln("Hello World!");
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.