1.1 入门
#include <stdio.h>
int main() {
printf("hello, world\n");
}
一个 C 语言程序,无论大小如何,都是由函数和变量组成
1.2 变量与算术表达式
注释、声明、变量、算术表达式、循环、格式化输出
#include <stdio.h>
int main() {
int fahr, celsius;
int lower, upper, step;
lower = 0; /* 温度表的下限 */
upper = 300; /* 温度表的上限 */
step = 20; /* 步长 */
fahr = lower;
while (fahr <= upper) {
celsius = 5 * (fahr - 32) / 9;
printf("%d\t%d\n", fahr, celsius);
fahr = fahr + step;
}
}
1.3 for语句
#include <stdio.h>
int main() {
int fahr;
for (fahr = 0 ; fahr <= 300; fahr = fahr + 20)
printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
}
1.4 符号常量
#define 名字 替换文本
#include <stdio.h>
#define LOWER 0 /* 表的下限 */
#define UPPER 300 /* 表的下限 */
#define STEP 20 /* 步长 */
int main() {
int fahr;
for(fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP)
printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
}
1.5 字符输入/输出
#include <stdio.h>
#include <stdio.h>
int main() {
int c;
c = getchar();
while (c != EOF) {
putchar(c);
c = getchar();
}
}
1.5.2 字符计数
#include <stdio.h>
#include <stdio.h>
int main() {
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
1.5.3 行计数
#include <stdio.h>
int main() {
int c, nl;
nl = 0;
while((c = getchar()) != EOF)
if (c == ‘\n‘)
++nl;
printf("%d\n", nl);
}
原文:https://www.cnblogs.com/zhourongcode/p/12657141.html