D语言实例代码
import std.stdio;
int main () {
/* local variable definition */
int a = 100;
/* check the boolean condition */
时间:2022-07-04
import std.stdio;
int main () {
/* local variable definition */
int a = 10;
/* check the boolean condition using if statement */
时间:2022-07-04
import std.stdio;
int main () {
/* local variable definition */
int a = 10;
/* do loop execution */
do {
if( a == 15) {
时间:2022-07-04
import std.stdio;
int main () {
/* local variable definition */
int a = 10;
/* while loop execution */
while( a < 20 ) {
时间:2022-07-04
import std.stdio;
int main () {
/* local variable definition */
int i, j;
for(i = 2; i<100; i++) {
for(j = 2; j <= (i/j); j++)
时间:2022-07-04
import std.stdio;
int main () {
/* local variable definition */
int a = 10;
/* do loop execution */
do{
writefln("value of a: %d", a);
时间:2022-07-04
import std.stdio;
int main () {
/* for loop execution */
for( int a = 10; a < 20; a = a + 1 ) {
writefln("value of a: %d", a);
时间:2022-07-04
import std.stdio;
void main () {
int[string] array1;
array1["test"] = 3;
array1["test2"] = 20;
时间:2022-07-04
import std.stdio;
void main () {
int[string] days =
[ "Monday" : 0,
"Tuesday" : 1,
时间:2022-07-04
import std.stdio;
void main () {
int[string] e;// associative array b of ints that are
e["test"] = 3;
时间:2022-07-04
import std.stdio;
void main () {
// an array with 5 elements.
double a[5] = 5;
double b[5] = 10;
double [] c;
时间:2022-07-04
import std.stdio;
void main () {
// an array with 5 elements.
double a[5];
a[] = 5;
writeln("Array a:",a);
时间:2022-07-04
import std.stdio;
void main () {
// an array with 5 elements.
double a[5] = [1000.0, 2.0, 3.4, 17.0, 50.0];
时间:2022-07-04
import std.stdio;
void main () {
// an array with 5 elements.
double a[5] = [1000.0, 2.0, 3.4, 17.0, 50.0];
时间:2022-07-04
import std.stdio;
void main () {
// an array with 5 rows and 2 columns.
int a[5][2] = [ [0,0], [1,2], [2,4], [3,6],[4,8]];
时间:2022-07-04
import std.stdio;
void main() {
int n[ 5 ]; // n is an array of 5 integers
// initialize elements of array n to 0
时间:2022-07-04
import std.stdio;
void main() {
int n[ 10 ]; // n is an array of 10 integers
// initialize elements of array n to 0
时间:2022-07-04
import std.stdio;
import std.string;
void main() {
string s = "H123Hello1";
string result = munch(s, "0123456789H");
时间:2022-07-04
import std.stdio;
import std.string;
void main() {
char[] s1 = "hello World ".dup;
writeln("Capitalized string of s1 is ",capitalize(s1));
时间:2022-07-04
import std.stdio;
import std.string;
void main() {
char[] s1 = "hello World ".dup;
writeln("indexOf of llo in hello is ",std.string.indexOf(s1,"llo"));
时间:2022-07-04
import std.stdio;
import std.string;
void main() {
char[] s1 = "hello world ".dup;
char[] s2 = "sample".dup;
时间:2022-07-04
import std.stdio;
void main() {
string s1 = "Hello";
string s2 = "World";
string s3 = "World";
时间:2022-07-04
import std.stdio;
void main(string[] args) {
string greeting1 = "Good";
writefln("Length of string greeting1 is %d",greeting1.length);
时间:2022-07-04
import std.stdio;
void main(string[] args) {
string greeting1 = "Good";
char[] greeting2 = "morning".dup;
时间:2022-07-04
import std.stdio;
void main(string[] args) {
string greeting1 = "Hello all";
writefln("%s",greeting1);
时间:2022-07-04
import std.stdio;
union Data {
int i;
float f;
char str[13];
};
void main( ) {
Data data;
data.i = 10;
时间:2022-07-04
import std.stdio;
union Data {
int i;
float f;
char str[20];
};
int main( ) {
Data data;
writeln( "Memory size occupied by data : ", data.sizeof);
时间:2022-07-04
import std.stdio;
struct Books {
char [] title;
char [] subject = "Empty".dup;
intbook_id;
char [] author = "Raj".dup;
时间:2022-07-04
import std.stdio;
struct Books {
char [] title;
char [] subject = "Empty".dup;
intbook_id = -1;
时间:2022-07-04
import std.stdio;
struct Books {
char [] title;
char [] author;
char [] subject;
intbook_id;
};
void main( ) {
时间:2022-07-04