C Primer Plus第五章课后练习答案

其他章节答案

//Project 1
#include 
#define S_M_PER 60
int main(void)
{
    int min_1,hour,min_2;
    printf("Please enter the minute: ");
    while(scanf("%d",&min_1)>0)
    {
        hour = min_1 / S_M_PER;
        min_2 = min_1 % S_M_PER;
        printf("%dh%dmin\n",hour,min_2);
        printf("Please enter the minute: ");
    }
    return 0;
 } 
//Project 2
#include 
int main(void)
{
    int a,b;
    printf("Please enter a number: ");
    scanf("%d",&a);
    printf("%d ",a);
    b=a+10;
    while(++a<=b)
        printf("%d ",a);
    printf("\nThat's' all.");
    return 0;
 } 
//Project 3
#include 
#define DAY_PER_WEEK 7
int main(void)
{
    int day_1,week,day_2;
    printf("Please enter a day's number:\n");
    while(scanf("%d",&day_1)>0)
    {
        week = day_1/DAY_PER_WEEK;
        day_2 = day_1%DAY_PER_WEEK;
        printf("%d days are %d weeks, %d days.\n",day_1,week,day_2);
    }
    printf("Error");
    return 0;
 } 
//Project 4
#include  
#define CENT_INCH 0.393700787
#define FEET_INCH 12
int main(void)
{
    float height,inch;
    int feet;
    printf("Enter a height in centimeters:");
    scanf("%f",height);
    while(height>0)
    {
        inch = height*CENT_INCH;
        feet = inch/12;
        inch = inch-feet*12;
        printf("%.1f cm = %d feet, %.1f inchs\n",height,feet,inch);
        printf("Enter a height in centimeters(<=0 to quit):");
        scanf("%f",height);
    }
    printf("bye");
    return 0;
}
//Project 5
#include 
int main(void)
{
    int count,sum,days;
    count = 0;
    sum = 0;
    printf("Please enter your work's day:");
    scanf("%d",&days);
    while(count++ < days)
        sum = sum + count;
    printf("sum = %d\n",sum);
    return 0;
}
//Project 6
#include 
int main(void)
{
    int count,sum,days;
    count = 0;
    sum = 0;
    printf("Please enter your work's day:");
    scanf("%d",&days);
    while(count++ < days)
        sum = sum + count*count;
    printf("sum = %d\n",sum);
    return 0;
}
//Project 7
#include 
double cube(double n);
int main(void)
{
    double n;
    printf("Please enter a floating-point number:");
    scanf("%lf",&n);
    printf("The number's cubic value is:%lf.",cube(n));
    return 0;
}
double cube(double n)
{
    n = n * n * n;
    return n;
}
//Project 8
#include 
int main(void)
{
    int a,b;
    printf("This program computes moduli.\n");
    printf("Enter an inter to serve as the second operand:");
    scanf("%d",&b);
    if(b>0)
    {
        printf("Now enter the first operand:");
        scanf("%d",&a);
        while(a>0)
        {
            printf("%d %% %d is %d",a,b,a%b);
            printf("Enter next number for first operand (<=0 to quit):");
            scanf("%d",&a);
        }   
    }
    printf("Done");
    return 0;
}
//Project 9
#include
int Temperatures(double f);
int main(void)
{
    double f;
    printf("Please enter a FaFahrenheit:");
    while((scanf("%lf",&f)) == 1)
    {
        Temperatures(f);
        printf("Please enter next FaFahrenheit(q to quit):");
    }
    return 0;
}
int Temperatures(double f)
{
    double c,k;
    const double c1 = 5.0;
    const double c2 = 9.0;
    const double c3 = 32.0;
    const double k1 = 273.16;
    c = c1 / c2 * (f - c3);
    k = c + k1;
    printf("The Fahrenheit is %.2lfF.\n",f);
    printf("The Centigrade is %.2lfF.\n",c);
    printf("The Kopen temperature is %.2lfF.\n",k);
    return 0;
}

你可能感兴趣的:(C Primer Plus第五章课后练习答案)