zoukankan      html  css  js  c++  java
  • C 程序设计语言 —— 第一章

    第 1 章 导言

    1.1 入门

    #include <stdio.h>
    
    int main() {
        printf("hello, world
    ");
    }
    

    一个 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	%d
    ", fahr, celsius);
                    fahr = fahr + step;
            }
    }
    
    • int 整数
    • float 浮点数
    • char 字符(一个字节)
    • short 短整型
    • long 长整型
    • double 双精度浮点型

    1.3 for语句

    #include <stdio.h>
    
    int main() {
            int fahr;
    
            for (fahr = 0 ; fahr <= 300; fahr = fahr + 20)
                    printf("%3d %6.1f
    ", 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
    ", fahr, (5.0/9.0)*(fahr-32));
    }
    

    1.5 字符输入/输出

    • 一次读写一个字符 getchar、putchar
      1.5.1 文件复制
    #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
    ", nc);
    }
    

    1.5.3 行计数

    #include <stdio.h>
    
    int main() {
            int c, nl;
    
            nl = 0;
            while((c = getchar()) != EOF)
                    if (c == '
    ')
                            ++nl;
            printf("%d
    ", nl);
    }
    
  • 相关阅读:
    iOS编程中比较两个日期的大小
    sqlite第三方类库:FMDB使用
    ios日期格式转换
    UISwipeGestureRecognizer 左右事件捕捉
    iOS7.0中UILabel高度调整注意事项
    【java基础】Java反射机制
    【struts2】ActionContext与ServletActionContext
    【struts2】OGNL
    【struts2】值栈(后篇)
    【struts2】值栈(前篇)
  • 原文地址:https://www.cnblogs.com/zhourongcode/p/12657141.html
Copyright © 2011-2022 走看看