開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの無料、light版)
- 言語: C
- コンパイラ: UNIX ccコンパイラ (汎用UNIX)
『実践プログラミング 第3版』 (Steve Oualline (著)、 望月 康司 (監修) (翻訳)、 谷口 功 (翻訳)、 オライリー・ジャパン、1998年、ISBN978-4900900646) II部(単純なプログラミング)の10章(Cプリプロセッサ)10.8(プログラミング実習)実習10-4を解いてみる。
実習10-4.
コード(TextWrangler)
#include <stdio.h> #define SWAPS(n,m) (n) += (m); (m) = (n) - (m); (n) -= (m) int main(){ int a,b; char line[100]; printf("2つの整数(a b)を入力: "); fgets(line,sizeof(line),stdin); sscanf(line,"%d %d",&a,&b); SWAPS(a,b); printf("交換後: a = %d, b = %d\n",a,b); return (0); }
入出力結果(Terminal)
$ cc -g -o sample sample.c $ ./sample 2つの整数(a b)を入力: 10 20 交換後: a = 20, b = 10 $
0 コメント:
コメントを投稿