home > さまざまな言語で数値計算 > 基本のき >

さまざまな言語で数値計算

Only Do What Only You Can Do

数値を表示する

VBScript

WScript.StdOut.Write 3 * 5 & vbNewLine
WScript.StdOut.WriteLine 3 * 5
WScript.Echo 3 * 5
Z:\>cscript 0101.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

15
15
15

JScript

WScript.StdOut.Write(3 * 5 + "\n");
WScript.StdOut.WriteLine(3 * 5);
WScript.Echo(3 * 5);
Z:\>cscript 0101.js
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

15
15
15

PowerShell

Write-Output (3 * 5)
Write-Host   (3 * 5)
Echo         (3 * 5)
Z:\>powershell -file 0101.ps1
15
15
15

Perl

print 3 * 5;
Z:\>perl 0101.pl
15

PHP

<?php
echo  3 * 5, "\n";
print 3 * 5;
?>
Z:\>php 0101.php
15
15

Python

print 3 * 5
Z:\>python 0101.py
15

Ruby

print 3 * 5, "\n"
puts 3 * 5
Z:\>ruby 0101.rb
15
15

Groovy

Pascal

Program Pas0101(arg);
begin
    writeln(3 * 5);
end.
Z:\>fpc Z:\Pas0101.pp
Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling Z:\Pas0101.pp
Linking Z:\Pas0101.exe
4 lines compiled, 0.5 sec , 26000 bytes code, 1612 bytes data

Z:\>Pas0101
15

Ada

VB.NET

Module VB0101
    Public Sub Main()
        Console.WriteLine(3 * 5)
    End Sub
End Module
Z:\>vbc VB0101.vb
Microsoft (R) Visual Basic Compiler version 10.0.30319.233
Copyright (c) Microsoft Corporation.  All rights reserved.


Z:\>VB0101
15

C#

public class CS0101
{
    public static void Main()
    {
        System.Console.WriteLine(3 * 5);
    }
}
Z:\>csc CS0101.cs
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.


Z:\>CS0101
15

Java

public class Java0101 {
     public static void main(String []args) {
        System.out.println(3 * 5);
     }
}
Z:\>javac Java0101.java

Z:\>java Java0101
15

C++

#include <iostream.h>

int main()
{
    cout << 3 * 5;
    return 0;
}
Z:\>bcc32 CP0101.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
CP0101.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

Z:\>CP0101
15

Objective-C

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
    printf("%d", 3 * 5);
    return 0;
}

Online で様々な言語を実行できるサイト "CompileOnline" (http://www.compileonline.com/) を使用.

Compiling the source code....
$gcc `gnustep-config --objc-flags` -L/usr/GNUstep/System/Library/Libraries -lgnustep-base main.m -o demo -lm -pthread -lgmpxx -lreadline 2>&1

Executing the program....
$demo
15

D

Go

Scala

object Scala0101 {
    def main(args:Array[String]) {
        println(3 * 5);
    }
}
Z:\>scala Scala0101.scala
15

F#

module Fs0101

printfn "%d" (3 * 5)
exit 0
Z:\>fsi Fs0101.fs

Microsoft (R) F# 2.0 Interactive build 4.0.40219.1
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

[Loading Z:\Fs0101.fs]
15

Clojure

(printf "%d\n" (* 3 5))
Z:\>java -cp C:\ProgramFiles\clojure-1.5.1\clojure-1.5.1.jar clojure.main Clj0101.clj
15

Haskell

main = print (3 * 5)
Z:\>ghc -o Hs0101 Hs0101.hs
[1 of 1] Compiling Main             ( Hs0101.hs, Hs0101.o )
Linking Hs0101.exe ...

Z:\>Hs0101
15

inserted by FC2 system