```The C Programming Language by Kernighan

Exercises

//c.h
typedef int I;typedef double F;typedef unsigned char C,*S;typedef long
L;typedef void V;
#define F(e...)   for(e)
#define W(c...)   while(c)
#define C(c,t...) if(c){t;}else
#define R         return
#define J(n,e...) {I j=0,Mj=(n);F(;j<Mj;++j){e;}}
#define K(n,e...) {I k=0,Mk=(n);F(;k<Mk;++k){e;}}
#define A(e...)   {if(!(e))R 0;}
#define P(c,e...) {if(c)R(e);}
#define E(c,e...) {if(c)R O("ERROR: %s\n",(e)),(S)0;}

#include<stdio.h>
#define GC()      getchar()
#define PC(x)     putchar(x)
#define I(e...)   scanf(e)
#define O(e...)   printf(e)

//e1-08. count ' ';'\t';'\n'
#include"c.h"
main(){I n=0,x;W((x=GC())!=EOF)C(x==' '||x=='\t'||x=='\n',++n);O("%d",n);}

//e1-09. '  ' to ' '
#include"c.h"
main(){F(I x=0,y;(y=GC())!=EOF;x=y)C(x!=y||y!=' ',PC(y));}

//e1-10. change '\b' to \b ; '\t' to \t ; '\\' to \\
#include"c.h"
main(){I
x;W((x=GC())!=EOF)C(x=='\t',O("\\t"))C(x=='\b',O("\\b"))C(x=='\\',O("\\\\"))PC(x
);}

//e1-12. print 1 word/line
#include"c.h"
main(){I x,b=0;W((x=GC())!=EOF)C(x=='
'||x=='\n'||x=='\t',C(b==1,b=0;PC('\n'))){PC(x);b=1;}}

//c1s6-ndwo. count [0-9]; ' '; others
#include"c.h"
main(){I
x,n[12];J(12,n[j]=0);W((x=GC())!=EOF)C(x>='0'&&x<='9',++n[x-'0'])C
(x==' '||x=='\n'||x=='\t',++n[10])++n[11];J(12,O("%d ",n[j]))}

//c1s7. run a power function
#include"c.h"
I f(I,I);I f(I x,I y){I z=1;K(1+y,z*=x);R z;}main(){J(12,O("%d\n",f(2,j)));}

//e1-15. run a fahrenheit to celsius function
#include"c.h"
F f(I);F f(I x){R 5.0*(x-32)/9;}main(){J(16,O("%d %f\n",20*j,f(20*j)))}

Sources

http://www.amazon.com/s?field-keywords=The-Programming-Language-Brian-Kernighan
```