zoukankan      html  css  js  c++  java
  • C Primer Plus_第三章_数据和C_复习题与编程练习

    Review

    long代替int类型变量的原因是什么?
    在您的系统中,long可以容纳比int更大的数;如果您确实需要处理更大的值,那么使用一种在所有系统上都保证至少是32位的类型会使程序的可移植性更好。(PS:用sizeof(int)查看我电脑中的int发现是4字符即32位,和long一样,但是long是标准的32位,int在我这64位的系统中定义的是32位,在其他系统可能是16位。无论如何,有个标准,最好按标准来设定,这样移植起来就方便)

    要获得一个32位的有符号整数,可以使用哪些可以值得数据类型?每种选择的原因是什么?
    要获得正好是32位的数,可以使用int32_t
    要获得可存储至少32位的最小类型,可使用int_least32_t
    要获得32位类型中提供最快计算速度的类型,可选择int_fast32_t


    Practice

    1.略

    2.


    #include
    int main(void)
    {
     //输入一个整数
     int i;
     printf("Please enter the value of i: ");
     scanf("%d",&i);
     printf("i = %d ", i);
     //将这个整数赋给一个字符,自动按照ascii码找到相应的字符
     char c = i;
     printf("the ASCII character of number %d is %c ", i, c);

     return 0;
    }

    3.


    #include
    #include
    #include

    int main(void)
    {
     printf("startled by the sudden sound,a Sally shouted, "By the Great Pumpkin, what was that!" ");
     printf("a");

     return 0;
    }

     

    4.


    #include
    int main(void)
    {
     float f;
     printf("Please enter a float: ");
     scanf("%f", &f);
     printf("f = %f and f also = %e ", f, f);

     return 0;
    }

     

    5.


    #include
    int main(void)
    {
     int i;
     double one_year = 3.156e7;
     printf("My master, please enter your age: ");
     scanf("%d",&i);
     printf("My master, you have been on the earth for about %f seconds! ", i*one_year);

     return 0;
    }

     

    7.


    #include
    int main(void)
    {
     float height;
     float one_inch = 2.54;
     printf("Please enter your height in centimiter my master: ");
     scanf("%f",&height);
     printf("My master, you're %1.2f cm high and that is %1.2f inch, so cool! ", height, height/one_inch);

     return 0;
    }

  • 相关阅读:
    SEO分享:我为什么会有这么多的优质外链资源?
    执行shell脚本提示“syntax error near unexpected token for((i=0;i<$length;i++))”
    Codeforces Round #254 (Div. 2)D(预计)
    自己写配置文件
    软件測试基本方法(二)之白盒測试
    hdu 4638 Group
    影视集结号--首页
    2015阿里巴巴秋招在线笔试题
    php 抓取天气情况 www.weather.com.cn
    C语言中的enum(枚举)使用方法
  • 原文地址:https://www.cnblogs.com/TomLily/p/5814586.html
Copyright © 2011-2022 走看看