第四章 4.3

4.3 常量和C预处理器

1.预处理器也可用来定义常量,格式如下:#define TAXRATE 0.015

2.#define指令还可定义字符字符串常量,前者使用单引号,后者使用双引号。

如:#define BEEP '\a'

      #define ESC "\033"

3.printf()函数打印数据的指令要与待打印数据的类型相匹配。例如,打印整数时使用%d,打印字符是使用%c,等等,详见p81

2.scanf()中%s和%f的用法

4.4//在披萨饼程序中定义已知的常量
#include<stdio.h>
#define PI 3.14159
int main(void)
{
    float area,circum,radius;

    printf("what is the radius of your pizza?\n");
    scanf("%f",&radius);  // 1.为什么有&?2.何时用%s? 何时用%f?
    area=PI*radius*radius;
    circum=2*PI*radius;
    printf("your basic pizza parameters are as follows:\n");
    printf("circumference=%1.2f,area=%1.2f",circum,area);
                              //%1.2f意思是结果四舍五入为两位小时输出。

    getchar();
    getchar();
    return 0;
}

发布了10 篇原创文章 · 获赞 0 · 访问量 2379

猜你喜欢

转载自blog.csdn.net/YBQ9558/article/details/88935508
4.3
今日推荐