整数と浮動小数点数
明解C言語 入門編 > 2. 演算と型 >
整数と浮動小数点数
C
#include <stdio.h>
int main(int argc, char* argv[])
{
int nx;
double dx;nx = 9.99;
dx = 9.99;printf(" int 型変数nxの値:%d\n", nx);
printf(" nx / 2:%d\n", nx / 2);printf("double型変数dxの値:%f\n", dx);
printf(" dx/2.0:%f\n", dx / 2.0);return 0;
}
実行結果
R:\>lesson010\project1.exe
int 型変数nxの値:9
nx / 2:4
double型変数dxの値:9.990000
dx/2.0:4.995000
C++
#include <iostream.h>int main(int argc, char* argv[])
{
int nx;
double dx;nx = 9.99;
dx = 9.99;cout << " int 型変数nxの値:" << nx << endl;
cout << " nx / 2:" << nx / 2 << endl;cout << "double型変数dxの値:" << dx << endl;
cout << " dx/2.0:" << dx / 2.0 << endl;return 0;
}
実行結果
T:\>lesson010\Project1.exe
int 型変数nxの値:9
nx / 2:4
double型変数dxの値:9.99
dx/2.0:4.995
Delphi
program Project1;{$APPTYPE CONSOLE}
uses
SysUtils;
var
nx: Integer;
dx: Double;
begin
nx := 9;
dx := 9.99;write(format(' int 型変数nxの値:%d'#13#10, [nx]));
write(format(' nx / 2:%d'#13#10, [nx div 2]));write(format('double型変数dxの値:%1.6f'#13#10, [dx]));
write(format(' dx/2.0:%1.6f'#13#10, [dx / 2.0]));
end.
実行結果
S:\>lesson010\project1.exe
int 型変数nxの値:9
nx / 2:4
double型変数dxの値:9.990000
dx/2.0:4.995000