C prime plus(第六版) 中文版 第十一章答案

第一题#include <stdio.h>#include <stdlib.h>int main(){ printf("12.9.1:\n"); printf("How many pounds to a firkin of butter?\n"); int units; while(scanf("%d",&units)==1...
摘要由CSDN通过智能技术生成

第一题

#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("12.9.1:\n");
    printf("How many pounds to a firkin of butter?\n");
    int units;
    while(scanf("%d",&units)==1){
        if(units==56){
            printf("You must have looked it up!\n");
            break;
        }
        else{
            printf("No luck, my friend. Try again.\n");
        }
    }
    return 0;
}

第二题

#include "pe12-2a.h"
#include <stdio.h>
#include <stdlib.h>

static int m;
static double s;
static double f;
void set_mode(int mode ){
    if(mode==0||mode==1){
        m=mode;
    }
    else{
        printf("Invalid mode specified. Mode %s used.\n", (m? "1US" : "0(metric)"));
    }
}
void get_info(){
    printf("Enter distance traveled in %s: ",m==0 ? "kilometers":"miles");
    scanf("%lf",&s);
    printf("Enter fuel consumed in %s: ",m==0 ? "liters":"gallons");
    scanf("%lf",&f);
}
void show_info(){
    if(m==0)
        printf("Fuel consumption is %.2f liters per 100km.\n",f/s*100);
    else if(m==1)
        printf("Fuel consumption is %.1f miles per gallons.\n",s/f);
}

#include "pe12-2a.h"
#include <stdio.h>
#include <stdlib.h>
int main(){
    int mode;
    printf("Enter 0 for metric mode, 1 for US mode: ");
    scanf("%d",&mode);
    while(mode >=0 ){
        set_mode(mode);
        get_info();
        show_info();
        printf("Enter 0 for metric mode, 1 for US mode(-1 tp quir): ");
        scanf("%d",&mode);
    }
    printf("Done!");
    return 0;
}

#ifndef PE12-2A_H
#define PE12-2A_H


       void set_mode(int );
       void get_info();
       void show_info();

#endif // PE12-2A_H

第三题

#include 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值