2012年9月10日月曜日

開発環境

『実践プログラミング 第3版』 (Steve Oualline (著)、 望月 康司 (監修) (翻訳)、 谷口 功 (翻訳)、 オライリー・ジャパン、1998年、ISBN978-4900900646) I部(基礎編)の6章(条件文と制御文)6.10(プログラミング実習)実習6-6を解いてみる。

実習6-6.

コード(TextWrangler)

#include <stdio.h>

int main(){
  int hour;
  int wage;
  int total;
  char line[100];
  printf("1週間の労働時間と時給を入力: ");
  fgets(line,sizeof(line),stdin);
  sscanf(line,"%d %d",&hour,&wage);
  total = hour * wage + (hour - 40) * 0.5 * wage;
  printf("賃金: %d\n",total);
  return (0);
}

入出力結果(Terminal)

$ cc -g -o sample sample.c
$ ./sample
1週間の労働時間と時給を入力: 50 2000
賃金: 110000
$

0 コメント:

コメントを投稿