開発環境
- 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-6を解いてみる。
その他参考書籍
- プログラミング言語C 第2版 ANSI規格準拠 (B.W. カーニハン D.M. リッチー (著)、 石田 晴久 (翻訳)、共立出版)
- プログラミング言語Cアンサー・ブック 第2版 (クロビス・L.トンド、スコット・E.ギンペル(著)、矢吹 道郎(翻訳))
実習 5-6.
コード
sample.c
#include <stdio.h>
int main(int argc, char *argv[])
{
int total_minutes;
int hour;
int minutes;
char line[100];
printf("時間を分(必ず整数)で入力: ");
fgets(line, sizeof(line), stdin);
sscanf(line, "%d", &total_minutes);
hour = total_minutes / 60;
minutes = total_minutes % 60;
printf("%d時間%d分\n", hour, minutes);
}
入出力結果(Terminal)
$ cc -g -o sample sample.c $ ./sample 時間を分(必ず整数)で入力: 90 1時間30分 $
0 コメント:
コメントを投稿