開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの無料、light版)
- 言語: C
- コンパイラ: UNIX ccコンパイラ (汎用UNIX)
『実践プログラミング 第3版』 (Steve Oualline (著)、 望月 康司 (監修) (翻訳)、 谷口 功 (翻訳)、 オライリー・ジャパン、1998年、ISBN978-4900900646) I部(基礎編)の4章(基本的な宣言および式)4.13(プログラミング実習)実習4-3を解いてみる。
実習4-3.
コード(TextWrangler)
#include <stdio.h>
float width;
float height;
int main(){
width = 3.0;
height = 5.0;
printf("長方形: 横%fインチ、縦%fインチ\n",width,height);
printf("面積: %fcm^2\n",((width * 2.54) * (height * 2.54)));
printf("外周: %fcm\n",(2 * (width + height) * 2.54));
return (0);
}
入出力結果(Terminal)
$ cc -g -o sample sample.c $ ./sample 長方形: 横3.000000インチ、縦5.000000インチ 面積: 96.774000cm^2 外周: 40.640000cm $
修正
コード(TextWrangler)
#include <stdio.h>
float width;
float height;
int main(){
width = 6.8;
height = 2.3;
printf("長方形: 横%fインチ、縦%fインチ\n",width,height);
printf("面積: %fcm^2\n",((width * 2.54) * (height * 2.54)));
printf("外周: %fcm\n",(2 * (width + height) * 2.54));
return (0);
}
入出力結果(Terminal)
$ cc -g -o sample sample.c $ ./sample 長方形: 横6.800000インチ、縦2.300000インチ 面積: 100.903025cm^2 外周: 46.228002cm $
0 コメント:
コメントを投稿