《C Prime Plus》(第六版) 第03章 编程练习 4 float 类型的格式化输出

C Prime Plus 第六版

第03章 编程练习 4

编译器版本:Mac Xcode 11.6 

4.  编写一个程序,读取一个浮点数,先打印成小数点形式,再打印成指数形式。然后,如果系统支持,再打印成p记数法(即十六进制计数法)。按以下格式输出(实际显示的指数位数因系统而异)

Enter a floating-poing value: 64.25

fixed-poing notation: 64.250000

exponential notation: 6.425000e+01

p notation: 0x1.0p+6

//
//  main.c
//  Ex04        Page 68
//
//  Created by turbo on 2021/5/4.
//  Copyright © 2021 LiangNuo Software Technology Co., LTD. All rights reserved.
//

/* 编写一个程序,读取一个浮点数,先打印成小数点形式,
 再打印成指数形式。然后,如果系统支持,再打印成p记数法(即
 十六进制计数法)。按以下格式输出(实际显示的指数位数因系统
 而异
 Enter a floating-poing value: 64.25
 fixed-poing notation: 64.250000
 exponential notation: 6.425000e+01
 p notation: 0x1.0p+6 */

#include <stdio.h>

int main(void)
{
    float fValue;
    printf("Enter a floating-point value: ");
    scanf("%f", &fValue);
    printf("fixed-poing notation: %f\n", fValue);
    printf("exponential notation: %e\n", fValue);
    printf("p notation: %a\n", fValue);
    
    return 0;
}

程序输出结果

Enter a floating-point value: 64.25
fixed-poing notation: 64.250000
exponential notation: 6.425000e+01
p notation: 0x1.01p+6
Program ended with exit code: 0

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值