2013年10月12日土曜日

開発環境

C実践プログラミング 第3版 (Steve Oualline (著)、 望月 康司 (監訳) (翻訳)、谷口 功 (翻訳)、オライリー・ジャパン)の7章(プログラミング手順)、7.15(プログラミング実習)、実習 7-4を解いてみる。

その他参考書籍

実習 7-4.

コード

sample.c

#include <stdio.h>
#include <math.h>
int main(int argc, char *argv[])
{
    int price;
    double vat_price;
    char line[100];
    printf("料金を入力: ");
    fgets(line, sizeof(line), stdin);
    sscanf(line, "%d", &price);
    vat_price = price * 1.05;
    /* 1円単位に丸める(小数点以下を四捨五入する)が上手くいってるかを確認
     * するために、丸め前と後を出力
     */
    printf("消費税込みの料金: %d円(%lf)\n", (int) round(vat_price), vat_price);
    return (0);
}

makefile

CC=cc
CFLAGS=-g

sample: sample.c
 $(CC) $(CFLAGS) -o sample sample.c

clean:
 rm -f sample

入出力結果(Terminal)

$ make
cc -g -o sample sample.c
$ ./sample
料金を入力: 10000
消費税込みの料金: 10500円(10500.000000)
$ ./sample
料金を入力: 11111
消費税込みの料金: 11667円(11666.550000)
$

0 コメント:

コメントを投稿