C Primer Plus4-6

/*6.编写一个程序,设置一个值为 1.0/3.0 的 double 类型变量和一个值为 1.0/3.0 的 float 类型变
量。每个变量的值显示三次:一次在小数点右侧显示 4 个数字,一次在小数点右侧显示 12 个数字,另一次
在小数点右侧显示 16 个数字。同时要让程序包括 float.h 文件,并显示 FLT—DIG 和 DBL_DIG 的值。 1.0/3.0
的显示值与这些值一致吗?*/

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

int main()
 {
    double a = 1.0 / 3.0;
    float b = 1.0 / 3.0;

    printf("%.4f\n", a);
    printf("%.12f\n", a);
    printf("%.16f\n\n", a);
    printf("%.4f\n", b);
    printf("%.12f\n", b);
    printf("%.16f\n\n", b);
    printf("FLT_DIG and DBL_DIG:%d and %d\n", FLT_DIG, DBL_DIG);

    system("pause");
    return 0;



} 

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值