#06:プログラムで計算する
ここでは、プログラムで計算する方法を学習します。まずは、整数の四則演算を試してみましょう。
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello world");
Console.WriteLine(100 + 30);
}
}
// => 130
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello world");
Console.WriteLine(100 - 30);
}
}
// => 70
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello world");
Console.WriteLine(100 * 30);
}
}
// => 3000
整数同士の割り算の答えは整数になります。
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello world");
Console.WriteLine(100 / 30);
}
}
// => 3
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello world");
Console.WriteLine(100 + 30 + 2);
}
}
// => 132
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello world");
Console.WriteLine(100 + 30 * 2);
}
}
// => 160
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello world");
Console.WriteLine((100 + 30) * 2);
}
}
// => 260