2つの変数に整数値を格納して表示

明解C言語 入門編 > 1. まずは慣れよう >

2つの変数に整数値を格納して表示

C


#include <stdio.h>
int main(int argc, char* argv[])
{
int vx, vy;

vx = 57;
vy = vx + 10;

printf("vxの値は%dです。\n", vx);
printf("vyの値は%dです。\n", vy);

return 0;
}

実行結果


R:\>lesson003\project1.exe
vxの値は57です。
vyの値は67です。

C++


#include <iostream.h>

int main(int argc, char* argv[])
{
int vx, vy;

vx = 57;
vy = vx + 10;

cout << "vxの値は" << vx << "です。\n";
cout << "vyの値は" << vy << "です。\n";

return 0;
}

実行結果


T:\>lesson003\project1.exe
vxの値は57です。
vyの値は67です。

Delphi


program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils;
var
vx, vy: Integer;
begin
vx := 57;
vy := vx + 10;

write(format('vxの値は%dです。'#13#10, [vx]));
write(format('vyの値は%dです。'#13#10, [vy]));
end.

実行結果


S:\>lesson003\project1.exe
vxの値は57です。
vyの値は67です。

Perl
$vx = 57;
$vy = $vx + 10;

print "vxの値は$vxです。\n";
print "vyの値は$vyです。\n";

実行結果

L:\>perl lesson_01_003.pl
vxの値は57です。
vyの値は67です。

Ruby
vx = 57
vy = vx + 10

print "vxの値は#{vx}です。\n"
print "vyの値は#{vy}です。\n"

実行結果

L:\>ruby l:\lesson_01_003.rb
vxの値は57です。
vyの値は67です。