ForNext
Only Do What Only You Can Do
006. 読み込んだ2つの整数値の 和・差・積・商・剰余 を表示
VBScript
JScript
Perl
更新日 : 2010.10.18
print "2つの整数を入力してください。\n"; print "整数1:"; chomp($vx = <STDIN>); print "整数2:"; chomp($vy = <STDIN>); print "vx + vy = ", $vx + $vy, "\n"; print "vx - vy = ", $vx - $vy, "\n"; print "vx * vy = ", $vx * $vy, "\n"; print "vx / vy = ", $vx / $vy, "\n"; print "vx % vy = ", $vx % $vy, "\n";
L:\>perl lesson_02_006.pl 2つの整数を入力してください。 整数1:57 整数2:21 vx + vy = 78 vx - vy = 36 vx * vy = 1197 vx / vy = 2.71428571428571 vx % vy = 15
PHP
更新日 : 2010.11.03
<?php print "2つの整数を入力してください。\n"; $fp = fopen("php://stdin", "r"); print "整数1:"; $vx = fgets($fp); print "整数2:"; $vy = fgets($fp); fclose($fp); echo "vx + vy = ", $vx + $vy, "\n"; echo "vx - vy = ", $vx - $vy, "\n"; echo "vx * vy = ", $vx * $vy, "\n"; echo "vx / vy = ", $vx / $vy, "\n"; echo "vx % vy = ", $vx % $vy, "\n"; ?>
L:\>php lesson_02_006.php 2つの整数を入力してください。 整数1:57 整数2:21 vx + vy = 78 vx - vy = 36 vx * vy = 1197 vx / vy = 2.71428571429 vx % vy = 15
Python
更新日 : 2010.11.17
# coding: Shift_JIS print "2つの整数を入力してください。" vx = raw_input("整数1:") vy = raw_input("整数2:") print "vx + vy = ", str(int(vx) + int(vy)) print "vx - vy = ", str(int(vx) - int(vy)) print "vx * vy = ", str(int(vx) * int(vy)) print "vx / vy = ", str(int(vx) / int(vy)) print "vx % vy = ", str(int(vx) % int(vy))
N:\>python lesson_02_006.py 2つの整数を入力してください。 整数1:57 整数2:21 vx + vy = 78 vx - vy = 36 vx * vy = 1197 vx / vy = 2 vx % vy = 15
Ruby
更新日 : 2010.11.01
puts "2つの整数を入力してください。" print "整数1:" vx = STDIN.gets.chomp.to_i print "整数2:" vy = STDIN.gets.chomp.to_i print "vx + vy = ", vx + vy, "\n" print "vx - vy = ", vx - vy, "\n" print "vx * vy = ", vx * vy, "\n" print "vx / vy = ", vx / vy, "\n" print "vx % vy = ", vx % vy, "\n"
L:\>ruby l:\lesson_02_006.rb 2つの整数を入力してください。 整数1:57 整数2:21 vx + vy = 78 vx - vy = 36 vx * vy = 1197 vx / vy = 2 vx % vy = 15
PowerShell
Scala
F#
C
更新日 : 2010.10.08
#include <stdio.h> int main(int argc, char* argv[]) { int vx, vy; puts("2つの整数を入力してください。"); printf("整数1:"); scanf("%d", &vx); printf("整数2:"); scanf("%d", &vy); printf("vx + vy = %d\n", vx + vy); printf("vx - vy = %d\n", vx - vy); printf("vx * vy = %d\n", vx * vy); printf("vx / vy = %d\n", vx / vy); printf("vx %% vy = %d\n", vx % vy); return 0; }
R:\>lesson006\project1.exe 2つの整数を入力してください。 整数1:57 整数2:21 vx + vy = 78 vx - vy = 36 vx * vy = 1197 vx / vy = 2 vx % vy = 15
C++
更新日 : 2010.10.13
#include <iostream.h> int main(int argc, char* argv[]) { int vx, vy; cout << "2つの整数を入力してください。" << endl; cout << "整数1:"; cin >> vx; cout << "整数2:"; cin >> vy; cout << "vx + vy = " << vx + vy << endl; cout << "vx - vy = " << vx - vy << endl; cout << "vx * vy = " << vx * vy << endl; cout << "vx / vy = " << vx / vy << endl; cout << "vx % vy = " << vx % vy << endl; return 0; }
T:\>lesson006\project1.exe 2つの整数を入力してください。 整数1:57 整数2:21 vx + vy = 78 vx - vy = 36 vx * vy = 1197 vx / vy = 2 vx % vy = 15
C++Builder
VC++
C#
Java
更新日 : 2010.11.05
import java.util.Scanner; class Lesson006 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); System.out.println("2つの整数を入力してください。"); System.out.printf("整数1:"); int vx = stdIn.nextInt(); System.out.printf("整数2:"); int vy = stdIn.nextInt(); System.out.printf("vx + vy = %d\n", vx + vy); System.out.printf("vx - vy = %d\n", vx - vy); System.out.printf("vx * vy = %d\n", vx * vy); System.out.printf("vx / vy = %d\n", vx / vy); System.out.printf("vx %% vy = %d\n", vx % vy); } }
L:\>java Lesson006 2つの整数を入力してください。 整数1:57 整数2:21 vx + vy = 78 vx - vy = 36 vx * vy = 1197 vx / vy = 2 vx % vy = 15
Objective-C
D
VB
VB.NET
Delphi
更新日 : 2010.09.24
program Project1; {$APPTYPE CONSOLE} uses SysUtils; var vx, vy: Integer; begin writeln('2つの整数を入力してください。'); write('整数1:'); read(vx); write('整数2:'); read(vy); write(format('vx + vy = %d'#13#10, [vx + vy])); write(format('vx - vy = %d'#13#10, [vx - vy])); write(format('vx * vy = %d'#13#10, [vx * vy])); write(format('vx / vy = %d'#13#10, [vx div vy])); write(format('vx %% vy = %d'#13#10, [vx mod vy])); end.
S:\>lesson006\project1.exe 2つの整数を入力してください。 整数1:57 整数2:21 vx + vy = 78 vx - vy = 36 vx * vy = 1197 vx / vy = 2 vx % vy = 15