2012年3月15日木曜日

開発環境

『実践プログラミング 第3版』 (Steve Oualline (著)、 望月 康司 (監修) (翻訳)、 谷口 功 (翻訳)、 オライリー・ジャパン、1998年、ISBN978-4900900646)の4章(基本的な宣言および式)(プログラミング実習)4.3(プログラミング実習4-2, 3を解いてみる。

4-2.

コード(TextWrangler)

#include <stdio.h>

int main()
{
 printf("*****\n");
 printf("*\n*\n");
 printf("*****\n");
 printf("*\n*\n");
 printf("*****\n");
 return (0);
}

入出力結果(Terminal)

$ cc -g -o c_program c_program.c
$ ./c_program
*****
*
*
*****
*
*
*****
$

4-3.

コード(TextWrangler)

#include<stdio.h>

int width;
int height;
float width_cm;
float height_cm;
float i2c;
int main(){
 width = 3;
 height = 5;
 i2c = 2.54;
 width_cm = width * i2c;
 height_cm = height * i2c;
 printf("横%dインチ、縦%dインチの長方形\n",width,height);
 printf("面積%fcm^2、外周%fcm\n",width_cm * height_cm,width_cm * 2 + height_cm * 2);
 
 return (0);
}

入出力結果(Terminal)

$ cc -g -o c_program c_program.c
$ ./c_program
横3インチ、縦5インチの長方形
面積96.773994cm^2、外周40.639999cm

コード(TextWrangler)

#include<stdio.h>

float width;
float height;
float width_cm;
float height_cm;
float i2c;
int main(){
 width = 6.8;
 height = 2.3;
 i2c = 2.54;
 width_cm = width * i2c;
 height_cm = height * i2c;
 printf("横%fインチ、縦%fインチの長方形\n",width,height);
 printf("面積%fcm^2、外周%fcm\n",width_cm * height_cm,width_cm * 2 + height_cm * 2);
 
 return (0);
}

入出力結果(Terminal)

$ cc -g -o c_program c_program.c
$ ./c_program
横6.800000インチ、縦2.300000インチの長方形
面積100.903023cm^2、外周46.227997cm

0 コメント:

コメントを投稿