c primer plus 3.11

1、

#include <stdio.h>
#include <float.h>
#include <limits.h>

int main(void)
{
int big_int = 2147483647;

float big_float = 3.4E38;

float small_float = 10.0/3;

printf("The big int data is %d\n", big_int + 1);

printf("The big float data is %f\n", big_float * 10);

printf("The big float data is %f\n", small_float);

printf("The MAX float data is %f\n", FLT_MAX);

printf("The max int data is %ld\n", INT_MAX);

return 0;    
} 

 

3.11-2

#include <stdio.h>

int main(void)
{
    int ch;
    
    printf("please input an number for char type: ");
    scanf("%d", &ch);
    
    printf("%d is equivalent to %c.\n", ch, ch);
    
    return 0;
}

 

 

3.11-3

#include <stdio.h>

int main(void)
{
    char alarm = '\a';
    printf("%c", alarm);
    
    printf("xxxxxxx.\n");
    printf("\"yyyyyyyyy\".\n");
    
    return 0;
}

 

 

3.11-4

#include <stdio.h>

int main(void)
{
    float test;
    
    printf("please input an float value: ");
    scanf("%f", &test);
    
    printf("fixed-point notation: %f.\n", test);
    printf("exponential notation: %e.\n", test);
    printf("p notation: %a.\n", test);
    
    return 0; 
}

 

3.11-5

#include <stdio.h>

#define SEC_PER_YEAR 3.156e7

int main(void)
{
    float age, second;
    
    printf("please input your age: ");
    scanf("%f", &age);
    
    second = SEC_PER_YEAR * age;
    
    printf("your age is %.2f.\n", age);
    printf("your age is equivalent to %e seconds.\n", second);
    
    return 0;
}

 

3.11-6

#include <stdio.h>

#define GRM_PER_MOLE 3.0e-23
#define GRM_PER_QUART 950

int main(void)
{
    float guart, gram, molecular;
    
    printf("please input the quarts: ");
    scanf("%f", &guart);
    
    gram = guart * GRM_PER_QUART;
    molecular = gram / GRM_PER_MOLE;
    
    printf("the number of water molecular: %e.\n", molecular);
    
    return 0;
}

 

3.11-7

#include <stdio.h>

#define CENTIMETER_PER_INCH 2.54

int main(void)
{
    float height_inch, height_centimeter;
    
    printf("please input your height in inch: ");
    scanf("%f", &height_inch);
    
    height_centimeter = height_inch * CENTIMETER_PER_INCH;
    
    printf("your height in centimeter is: %.1f.\n", height_centimeter);
    
    return 0;
}

 

3.11-8

#include <stdio.h>

int main(void)
{
    float cups;
    
    printf("please input cups: ");
    scanf("%f", &cups);
    
    printf("pint: %.1f\n", cups/2);
    printf("ounce: %.1f\n", cups * 8);
    printf("big spoon: %.1f\n", cups * 8 * 2);
    printf("tea spoon: %.1f\n", cups * 8 * 2 * 3);
    
    return 0; 
}

 

posted @ 2021-07-27 23:26  小鲨鱼2018  阅读(42)  评论(0编辑  收藏  举报