開発環境
- OS X Lion - Apple (UNIX) (OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C (プログラミング言語)
- Clang (コンパイラ)
C実践プログラミング 第3版 (Steve Oualline (著)、 望月 康司 (監訳) (翻訳)、谷口 功 (翻訳)、オライリー・ジャパン)の5章(配列、修飾子および数値の使用)、5.16(プログラミング実習)、実習 5-4を解いてみる。
その他参考書籍
- プログラミング言語C 第2版 ANSI規格準拠 (B.W. カーニハン D.M. リッチー (著)、 石田 晴久 (翻訳)、共立出版)
- プログラミング言語Cアンサー・ブック 第2版 (クロビス・L.トンド、スコット・E.ギンペル(著)、矢吹 道郎(翻訳))
実習 5-4.
コード
sample.c
#include <stdio.h> int main(int argc, char *argv[]) { double mph; double kph; char line[100]; printf("時間あたりのマイル数を入力: "); fgets(line, sizeof(line), stdin); sscanf(line, "%lf", &mph); kph = mph / 0.6213712; printf("時間あたりのキロメートル数に換算: %lfkm\n", kph); return (0); }
入出力結果(Terminal)
$ cc -g -o sample sample.c $ ./sample 時間あたりのマイル数を入力: 50 時間あたりのキロメートル数に換算: 80.467199km $ ./sample 時間あたりのマイル数を入力: 5.6 時間あたりのキロメートル数に換算: 9.012326km $
0 コメント:
コメントを投稿