Macでは、次の手順で gcc (Cコンパイラ)をインストールできます。
インストールの際には、インターネットに接続されている必要があります。
$ gcc次のウィンドウが表示されたら、「インストール」をクリックします。
$ gcc --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 10.0.0 (clang-1000.10.44.4) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin
// triarea --- area of triangle #include <stdio.h> double triarea(double w, double h) { double s; s = (w * h) / 2.0; return s; } int main(void) { double w, h, s; printf("w> "); scanf("%lf", &w); printf("h> "); scanf("%lf", &h); s = triarea(w, h); printf("triarea = %g\n", s); return 0; }
$ cd Documents/ $ ls ... triarea.c
$ gcc triarea.c $ ./a.out w> 7 h> 5 triarea = 17.5