1.5.1 Word Counting(The wrong version)

#include <stdio.h> #define OUT 0 /* outside word */ #define IN 1 /* inside word */ int main(void) { int c, nw; nw = 0; while((c = getchar()) != EOF) { while ((c >= 'a' &amp;&amp; c <= 'z') || (c >= 'A' &amp;&amp; c <= 'Z')) ; +...
2009-02-13 13:53 | 阅读 1567 次 | 评论 0 条

Exercise 1-10

/* Write a program to copy its input to its output,replacing each tab by \t, *each backspace by \b,and each backslash by \\ .This makes tabs and backspaces *visible in an unambiguous way */ #include <stdio.h> int main(void) { int c; while ((c = getchar()) != EOF) { if...
2009-02-13 11:51 | 阅读 1631 次 | 评论 0 条

Exercise 1-9

/*Write a program to copy its input to its output, *replacing each string of one or more blanks by a single blank*/#include <stdio.h> #define OUT 1 /* outside the word */#define IN 0 /* inside the word */ int main(void){ int c,state; state = OUT; while ((c = getchar()) != EO...
2009-02-13 11:35 | 阅读 1715 次 | 评论 0 条

Exercise 1-8

/* Write a program to count blanks,tabs,and newlines */ #include <stdio.h> int main(void) { int c, nb, nt, nn; nb = nt = nn = 0; while((c = getchar()) != EOF) { if (c == ' ') ++nb; if (c == '\t') ++nt; if (c == '\n') ++nn; } print...
2009-02-13 10:24 | 阅读 1318 次 | 评论 0 条

1.5.3 Line Counting

/* 1st version */ #include <stdio.h> int main(void) { int c, nl; nl = 0; while ((c = getchar()) != EOF) if (c == '\n') ++nl; printf("%d",nl); getch(); return 0; } =========================== /* 2nd version */ #include <stdio.h...
2009-02-13 10:17 | 阅读 1532 次 | 评论 0 条

1.5.2 Character Counting

/* 1st version */ #include<stdio.h> int main(void) { int c, nc; nc = 0; while((c = getchar()) !=EOF) { ++nc; } printf("%d",nc); getch(); return 0; } ====================== /* 2nd version */ #include <stdio.h> int main(v...
2009-02-13 10:03 | 阅读 1597 次 | 评论 0 条

Exercise 1-7

/* Write a program to print the value of EOF */ /* 1st version */ #include <stdio.h> int main(void){ int c; c = EOF; printf("the value of EOF is %d",c); getch(); return 0;} ===============/* 2nd version */ #include <stdio.h> int main(void){ printf("...
2009-02-13 09:54 | 阅读 1273 次 | 评论 0 条

1.5.1 File Copying

/* 1st verion.copy input to output */ #include <stdio.h> int main (void){ int c; c = getchar(); while (c != EOF) { putchar(c); c = getchar(); } return 0;} =========================== /* 2ed version.copy input to output */ #include <stdio.h> ...
2009-02-13 09:47 | 阅读 1157 次 | 评论 0 条

1.4 Symbolic Constants

/* The version of symbolic constants : print Fahrenheit-celsious table */ #include<stdio.h> #define LOWER 0#define UPPER 300#define STEP 20 int main(viod){ float fahr; for (fahr = LOWER; fahr <= UPPER; fahr += STEP ) { printf("%3.0f%6.1f\n", fahr, (5.0/9.0) * ( f...
2009-02-13 09:28 | 阅读 1216 次 | 评论 1 条

Exercise 1-5

/* Modify the temperature conversion program to print the table in reverse order, *that is form 300 degrees to 0. */ #include <stdio.h> int main(void){ float fahr; for(fahr = 300; fahr >= 0; fahr-=20) { printf("%3.0f%6.1f\n",fahr,(5.0/9.0) * (fahr - 32)); } ...
2009-02-13 09:12 | 阅读 1221 次 | 评论 0 条

1.3 The for statement

/* the version of for statement;print Fahrenheit - Celsius table */ #include <stdio.h> int main(void){ float fahr; for ( fahr = 0; fahr <=300; fahr+=20) { printf("%3.0f%6.1f\n",fahr,(5.0/9.0)*(fahr-32)); } getch(); return 0;}
2009-02-13 08:59 | 阅读 1547 次 | 评论 0 条

Exercise 1-4

/* Write a program to print the corresponding Celsius to Fahrenhei table */ #include <stdio.h> int main(void){ float cels, fahr; int lower, upper, step; lower = 0; upper = 100; step = 10; cels = lower; while ( cels <= upper) { fahr = 9 * cels / 5 + 3...
2009-02-13 08:52 | 阅读 1423 次 | 评论 0 条

Exercise 1-3

/* Modify the temperature conversion program to print a heading above the table */ #include <stdio.h> int main(void){ float fahr, cels; int lower, upper, step; lower = 0 ; upper = 300; step = 20; fahr = lower; printf("F\tC\n"); while (fahr <= upper) { ...
2009-02-13 08:38 | 阅读 1119 次 | 评论 0 条

1.2 Variables and Arithmetic Expressions

The program uses the formula [ Celsius = (5/9) * (Fahrenheit - 32)] to print the following table of Fahrenheit temperatures and their centigrade or Celsius equivalents: ============= /* print Fahrenheit - Celsius table for fahr =0, 20, ..., 300 */ #include <stdio.h> int main(void) { ...
2009-02-13 08:24 | 阅读 1370 次 | 评论 0 条

1.1 Getting Started

the program to print "hello, world" ============== #include <stdio.h> int main(void) { printf("hello, world"); return 0; }
2009-02-13 07:52 | 阅读 1118 次 | 评论 0 条
浏览27709次
文章归档