開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの無料、light版)
- 言語: C
- コンパイラ: UNIX ccコンパイラ (汎用UNIX)
『実践プログラミング 第3版』 (Steve Oualline (著)、 望月 康司 (監修) (翻訳)、 谷口 功 (翻訳)、 オライリー・ジャパン、1998年、ISBN978-4900900646) の12章(高度な型)12.9(プログラミング実習)j実習12-2.を解いてみる。
実習12-2.
コード(TextWrangler)
#include <stdio.h> struct date{ unsigned short int day; unsigned short int hour; unsigned short int minute; }; struct date date1 = {10,11,12}; struct date date2 = {11,12,13}; int f(struct date date1, struct date date2){ int n; n = (date2.hour - date1.hour) * 60 + (date2.minute - date1.minute); if(n < 0){ n *= -1; } return (n); } int main(){ struct date dates[2]; int i; dates[0] = date1; dates[1] = date2; for(i = 0; i < 2; i++){ printf("date%d: %d日%d時%d分\n", i,dates[i].day,dates[i].hour,dates[i].minute); } printf("2つの時刻の違い: %d分\n",f(dates[0],dates[1])); return (0); }
入出力結果(Terminal)
$ ./sample date0: 10日11時12分 date1: 11日12時13分 2つの時刻の違い: 61分 $
0 コメント:
コメントを投稿