c primer plus 第五章编程练习

1

#include 
#include 

const int M_PER_HOUR = 60;

int main(void) {
    int minutes;
    int hours;
    printf("input minutes\n");
    scanf("%d", &minutes);
    while (minutes > 0) {
        hours = minutes / M_PER_HOUR;
        minutes = minutes % M_PER_HOUR;
        printf("equals to %d hours %d minutes", hours, minutes);
        printf("print minutes\n");
        scanf("%d", &minutes);
    }

    return 0;
}

2

#include 
#include 

int main(void) {
    int number, target;
    printf("input number\n");
    scanf("%d", &number);
    target=number+10+1;

    while (number < target) {
        printf("%d\t", number);
        number++;
    }

    return 0;
}

3

几乎等同于题目1。忽略

4

#include 
#include 

const float H_TO_I = 2.54;
const float H_TO_F = 30.48;


int main(void) {
    float heightInInches, heightInCentimeters;
    int heightInFeet;
    printf("Enter a height in centimeters:\n");
    scanf("%f", &heightInCentimeters);

    while (heightInCentimeters > 0) {
        heightInFeet = (int) (heightInCentimeters / H_TO_F);
        heightInInches = (heightInCentimeters-(heightInFeet*H_TO_F))/H_TO_I;
        printf("feet %d, inch %.1f\t", heightInFeet, heightInInches);
        printf("Enter a height in centimeters:\n");
        scanf("%f", &heightInCentimeters);
    }

    return 0;
}

5

#include 
#include 

int main(void) {
    int count, sum, days;
    count = 0;
    sum = 0;
    printf("Enter days: ");
    scanf("%d", &days);
    while (count++ < days) {
        sum = sum + count;
    }
    printf("%d", sum);
}

你可能感兴趣的:(c primer plus 第五章编程练习)