D Programming – Arithmetic Operations Basics

One of the most used syntax in a language are the arithmetic operations. Operations like addition, subtraction, multiplication, division, and modulus are the basics. Below is a program I created that shows the basic syntax. I first declared two variables named x and y.  Then I performed the arithmetic operations using each variables in the following lines.

The code is below:

import std.stdio;

int main(){
	int x = 5, y = 2;
	writeln("x = ", x, " and y = ", y);
	writeln("x + y = ", x + y);
	writeln("x - y = ", x - y);
	writeln("x * y = ", x * y);
	writeln("x / y = ", x / y);
	writeln("x % y = ", x % y);
	
	return 0;
}

 

Run the Program.

The output should be same as below:

 

D-arith

 

Thank you for reading this short post.

Don’t forget to leave a comment.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s