C Primer Plus 第六版第四章编程练习答案

部分习题代码丢失,需要请联系博主。
编译环境:Visual Studio 2017

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<float.h>
#include<math.h>
void lifang(double x);
void Temperatures(double a);
******************************************************************************
/* practice 1      
void p4_1(void)
{
    char last_name[20],first_name[20];
    printf("Please input your name:");
    printf("_____________\b\b\b\b\b\b\b\b\b\b\b\b\b");
    scanf("%s %s", first_name,last_name);
    printf("your name is %s %s", first_name,last_name);
    system("pause");    
}

/* practice 2      
void p4_2(void)
{
    char name[20];
    int num;
    printf("Please input your name:\n");
    scanf("%s", name);
    num = strlen(name);
    printf("Your name is \"%s\"\n", name);
    printf("Your name is \"%20s\"\n", name);
    printf("Your name is \"%-20s\"\n", name);
    printf("Your name is \"%*s\"\n",num+3,name);
    system("pause");
}

/* practice 3      
void p4_3(void)
{
    float num=21.12345;
    printf("Please input a float number:\n");
    printf("The input is %3.1f or %.1e\n", num, num);
    printf("The input is %+.3f or %.3E",num,num);
    system("pause");    
}

/* practice 4      
void p4_4(void)
{
    char name[20];
    float old;
    printf("Please input your name and years-old:\n");
    scanf("%s %f", name, &old);
    printf("%s, you are %.3f feet tall", name, old);
    system("pause");
}

/* practice 5      
void p4_5(void)
{
    float speed, size;
    printf("Please input the speed,size:\n");
    scanf("%f %f", &speed, &size);
    printf("At %.2f m per second, a file of %.2f m download in %.2f seconds\n",
        speed, size, size / speed);
    system("pause");
}

/* practice 7      
void p4_7(void)
{
    double a = 1.0 / 3.0;
    float b = 1.0 / 3.0;
    printf("a=%.6f,b=%.6f\n", a, b);
    printf("a=%.12f,b=%.12f\n", a, b);
    printf("a=%.16f,b=%.16f\n", a, b);
    printf("float precision = %d digits\n", FLT_DIG);
    printf("double precision = %d digits\n", DBL_DIG);
    system("pause");
}

/* practice 8      
void p4_8(void)
#define j2s 3.785
#define y2k 1.609
{
    float distance, content;
    printf("Please input distance and content:\n");
    scanf("%f %f", &distance, &content);
    printf("one jialun can suport %.1f mile\n", distance / content);
    printf("one s can suport %.1f k\n", (j2s*distance)/(y2k*content));
    system("pause");
}

2018.5.16

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值