c prime plus 课后编程习题第5章答案

5-1

#include <stdio.h>
#define MIN 60
int main(void)
{
    int m,min,hours;
    printf("please enter minutes:");
    scanf("%d",&m);
    while(m > 0)
    {
         hours = m / MIN;
         min = m % MIN;
         printf("%d hours and %d minutes\n",hours,min);
         printf("enter minutes again:");
         scanf("%d",&m);
    }
    printf("quit\n");
    return 0;
}

5-2

#include <stdio.h>
int main(void)
{
    int i,a;
    printf("please input an number:");
    scanf("%d",&i);
    a = i + 10;
    while(i <= a)
    {
        printf("%d\n",i);
        i++;
    }
    return 0;
}

5-3

#include <stdio.h>
#define DAYS 7
int main(void)
{
    int d,weeks,days;
    printf("please enter d:");
    scanf("%d",&d);
    while(d > 0)
    {
         weeks = d / DAYS;
         days = d % DAYS;
         printf("%d weeks and %d days\n",weeks,days);
         printf("enter days again:");
         scanf("%d",&d);
    }
    printf("quit\n");
    return 0;
}

5-4

#include <stdio.h>
#define FEET 30.48
#define INCH 2.54
int main(void)
{
    float h, inch;
    int feet;

    printf("Enter a height in centimeters(<=0 to quit):\n");
    scanf("%f",&h);
    while (h > 0)
    {
        feet = h / FEET;
        inch = (h-feet*FEET) / INCH; 
        printf(" %d feet, %.1f inches\n",feet,inch);
        printf("Enter a height in centimeters(<0 to quit):\n");
        scanf("%f",&h);
    }
    printf("bye\n");

    return 0;
}





5-5

#include <stdio.h>
int main(void)
{
    int i,count,num;
    scanf("%d",&i);
    count = 0;
    num = 0;

    while(count <= i)
    {
        num = num + count;
        count++;
    }
    printf("%d\n",num);
     return 0;
}


    
   
    
   



5-6

 #include <stdio.h>
int main(void)
{
    int i,count,num;
    scanf("%d",&i);
    count = 0;
    num = 0;

    while(count <= i)
    {
        num = num + count * count;
        count++;
    }
    printf("%d\n",num);
     return 0;
}


    
   
    
   



5-7

#include <stdio.h>
void cubed(double n);
int main(void)
{
    double i;
    scanf("%lf",&i);   
    cubed(i);

    return 0;
}

void cubed(double n)
{
     printf("%lf\n",n * n * n);
}


    
   
    
   



5-8

#include <stdio.h>
int main(void)
{
    int i,n;
    printf("this program computes moduli.\n");
    printf("enter an integer to serve as the second operand:");
    scanf("%d",&i);
    printf("now enter the first operand:");
    scanf("%d",&n);
    printf("%d %% %d is %d\n",n,i,n % i);

    while(n > 0)
    {
        printf("enter next number for first operand(<= 0 to quit):");
        scanf("%d",&n);
        printf("%d %% %d is %d\n",n,i,n % i);
    }
    printf("done!\n");
    
    return 0;
}

5-9

#include <stdio.h>
void Temperatures(double n);
int main(void)
{
    double huashi;
    while(scanf("%lf",&huashi) == 1)   
    {
       Temperatures(huashi);
       printf("please enter temperatures again:");
    }
    printf("quit\n");

    return 0;
}

void Temperatures(double n)
{
    const double d = 273.16;
    double sheshi,kaishi;
    sheshi = (5.0 / 9.0) * (n - 32.0);
    kaishi = sheshi + d;
    printf("%.2lf  %.2lf %.2lf\n",n,sheshi,kaishi);
}

    
   
    
   



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值