当前位置:网站首页>Input and output of floating point data (C language)
Input and output of floating point data (C language)
2022-07-07 08:29:00 【It's a dream, it's you!】
Catalog
1 Input of floating point data
1.2 Double precision and long double precision
2.1 The default output of floating point numbers
2.2 Specify the output format %m . n f
1 Input of floating point data
1.1 Single precision input
(1) Format 1
Format controller :%f、%e、%g( or %F、%E、%G)Example :float f1,f2;scanf("%f%f",&f1,&f2); //%f for %e or %gSuch as the input : 3.14159 and 5.3, The input format is :The correct sample 3.14159 5.3 // Default white space separationThe wrong sample :3.14159 , 5.3(2) Format 2Change to the following form :scanf("f1=%f ,f2=%f ",&f1,&f2);Enter examples correctly : f1=3.14159 ,f2=5.31.2 Double precision and long double precision
double Controller :%lf、%le、%lg etc. .double d;scanf("%lf",&d);long double Controller :%Lf、%Le、%Lg etc. .long double Ld;scanf(“%Lf”,&Ld);
2 Floating point data output
2.1 The default output of floating point numbers
float、double Controller :%ffloat f=5.6f;double d=314.159;printf("f=%f,d=%f",f,d); // Can not write %FVC++6.0 in , The default output is after the decimal point 6 position . The result is :f=5.600000,d=314.1590002.2 Specify the output format %m . n f
Format Total seat width The fractional part Alignment mode%m.nf m n Right%-m.nf m n Left%.nf There is no limit n RightDefault right alignment , rounding2.3 Output example
float f1=3.14159f;printf("f1=%.3f",f1);Output results : f1=3.142printf("f1=%.0f",f1); Indicates that only integer parts are output .Output results : f1=3
3 Case study
3.1 Case study
【 Case study 】 Enter the radius and height of the bottom circle of the cylinder from the keyboard , Calculate and inputFigure out the volume of the cylinder ( After decimal point 2 position ).
#include<stdio.h>
const float PI=3.14f;
int main(void)
{
float r,h,v;
printf("Input radius and height:\n");
scanf("r=%f,h=%f",&r,&h);
v=PI*r*r*h;
printf("volume=%.2f\n",v);
return 0;
}
边栏推荐
- 单元测试报告成功率低
- GFS分布式文件系统
- [quick start of Digital IC Verification] 13. SystemVerilog interface and program learning
- Train your dataset with swinunet
- 单场带货涨粉10万,农村主播竟将男装卖爆单?
- BiSeNet的特点
- Learn how to compile basic components of rainbow from the source code
- 2-3 lookup tree
- Deit learning notes
- Ebpf cilium practice (1) - team based network isolation
猜你喜欢

一文了解如何源码编译Rainbond基础组件

GFS分布式文件系统

Application of slip ring of shipborne radar antenna

探索STEAM艺术设计中的创造力

The field value in Splunk subquery fuzzy matching CSV is*

解析机器人科技发展观对社会研究论
![[quick start of Digital IC Verification] 11. Introduction to Verilog testbench (VTB)](/img/c2/32a2c1ede493b778a6c44077d765d0.png)
[quick start of Digital IC Verification] 11. Introduction to Verilog testbench (VTB)

解析创新教育体系中的创客教育

JS copy picture to clipboard read clipboard

opencv学习笔记二——图像基本操作
随机推荐
Interface as a parameter (interface callback)
Open3d ISS key points
Opencv learning note 5 - gradient calculation / edge detection
一文了解如何源码编译Rainbond基础组件
In go language, function is a type
使用BiSeNet实现自己的数据集
Analysis of maker education in innovative education system
数据中台落地实施之法
Vulnerability recurrence easy_ tornado
Ebpf cilium practice (1) - team based network isolation
解析创新教育体系中的创客教育
单场带货涨粉10万,农村主播竟将男装卖爆单?
Go语言中,函数是一种类型
使用 Nocalhost 开发 Rainbond 上的微服务应用
GFS分布式文件系统
IP guard helps energy enterprises improve terminal anti disclosure measures to protect the security of confidential information
Practice of combining rook CEPH and rainbow, a cloud native storage solution
Pytoch (VI) -- model tuning tricks
Application of slip ring of shipborne radar antenna
Pvtv2--pyramid vision transformer V2 learning notes