C primer Plus Chap 03

C primer Plus Chap 03

C primer Plus 第三章代码与练习记录。

数据和C

  • xt1.c
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    /*整数上溢,浮点数上溢和浮点数下溢*/
    #include <stdio.h>
    int main(void)
    {
    /*查看int的字长*/
    printf("type int has a size of %lu bytes.\n",sizeof(int));
    int intoverflow = 2147483647;
    printf("the number is %d.\n",intoverflow);
    intoverflow = intoverflow + 1;
    printf("int overflow + 1 vavlue = %d.\n",intoverflow);
    return 0;
    }
    输出结果:
    1
    2
    3
    type int has a size of 4 bytes.
    the number is 2147483647.
    int overflow + 1 vavlue = -2147483648.
  • xt2.c
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    /*xt2.c--输入一个ASCII码值,输入相应的字符*/
    #include <stdio.h>
    int main(void)
    {
    int number;
    printf("please enter a number:\n");
    scanf("%d",&number);
    printf("the number %d is character %c.\n",number,number);
    return 0;
    }
    输出结果:
    1
    2
    3
    please enter a number:
    100
    the number 100 is character d.
  • xt3.c
    1
    2
    3
    4
    5
    6
    7
    /*xt3.c--编写程序发出警报声,并打印文字*/
    #include <stdio.h>
    int main(void)
    {
    printf("\astartled by the sudden sound, sally shouted. \"by the great pumpkin, what was that!\"\n");
    return 0;
    }
    输出结果:
    1
    startled by the sudden sound, sally shouted. "by the great pumpkin, what was that!"
  • xt4.c
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    /*xt4.c--读入一个浮点数,分别以小数形式和指数形式打印*/
    #include <stdio.h>
    int main(void)
    {
    float number;
    printf("please enter a number:");
    scanf("%f",&number);
    printf("the number is %f.\n",number);
    printf("the number %f can be writeen by %e.\n",number,number);
    return 0;
    }
    输出结果:
    1
    2
    3
    please enter a number:15
    the number is 15.000000.
    the number 15.000000 can be writeen by 1.500000e+01.
  • xt5.c
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    /*xt5.c*/
    #include <stdio.h>
    int main(void)
    {
    double s = 3.156e7;
    printf("%lf\n",s);
    double secound,age;
    printf("please enter your age:\n");
    scanf("%lf",&age);
    secound = s * age;
    printf("your age %lf is %lf secound\n",age,secound);

    return 0;
    }
    输出结果:
    1
    2
    3
    4
    31560000.000000
    please enter your age:
    33
    your age 33.000000 is 1041480000.000000 secound
  • xt6.c
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    #include <stdio.h>
    int main(void)
    {
    float hydrone=3.0e-23;
    float quart;
    printf("please enter a number:\n");
    scanf("%f",&quart);
    printf("%e\n",(950*quart)/hydrone);

    return 0;
    }
    输出结果:
    1
    2
    3
    please enter a number:
    16
    5.066666e+26
  • xt7.c
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    #include <stdio.h>
    int main(void)
    {
    float height;
    printf("please enter your height\n");
    scanf("%f",&height);
    printf("your height %.2f inch is about %.2f cm.\n",height,height*2.54);

    return 0;
    }
    输出结果:
    1
    2
    3
    please enter your height
    175
    your height 175.00 inch is about 444.50 cm.

C primer Plus Chap 03
https://ywmy.xyz/2022/05/07/C-primer-Plus-Chap-03/
作者
ian
发布于
2022年5月7日
许可协议