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