ForNext
Only Do What Only You Can Do
060. 整数の2乗と浮動小数点数2乗 (関数マクロ)
VBScript
JScript
Perl
PHP
Python
Ruby
PowerShell
Scala
F#
C
更新日 : 2010.10.08
#include <stdio.h> #define sqr(x) ((x) * (x)) int sqr_int(int x) { return x * x; } double sqr_double(double x) { return x * x; } int main(int argc, char* argv[]) { int nx = 3; double dx = 4.25; printf("%d * %d = %d\n", nx, nx, sqr_int(nx)); printf("%d * %d = %d\n", nx, nx, sqr(nx)); putchar('\n'); printf("%lf * %lf = %lf\n", dx, dx, sqr_double(dx)); printf("%lf * %lf = %lf\n", dx, dx, sqr(dx)); putchar('\n'); return 0; }
R:\>lesson060\Project1.exe 3 * 3 = 9 3 * 3 = 9 4.250000 * 4.250000 = 18.062500 4.250000 * 4.250000 = 18.062500