当前位置:网站首页>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;
}
边栏推荐
- OpenVSCode云端IDE加入Rainbond一体化开发体系
- iptables 之 state模块(ftp服务练习)
- [kuangbin]专题十五 数位DP
- [IELTS speaking] Anna's oral learning records Part3
- 单场带货涨粉10万,农村主播竟将男装卖爆单?
- Grpc, oauth2, OpenSSL, two-way authentication, one-way authentication and other column directories
- 【雅思口语】安娜口语学习记录 Part2
- 在 Rainbond 中一键安装高可用 Nacos 集群
- Open3d ISS key points
- Interview questions (CAS)
猜你喜欢
Train your dataset with swinunet
Bisenet features
Golang compilation constraint / conditional compilation (/ / +build < tags>)
一种适用于应用频繁测试下快速查看Pod的日志的方法(grep awk xargs kuberctl)
Practice of combining rook CEPH and rainbow, a cloud native storage solution
Rainbond 5.6 版本发布,增加多种安装方式,优化拓扑图操作体验
The single value view in Splunk uses to replace numeric values with text
Opencv learning notes 1 -- several methods of reading images
Open3D ISS关键点
Xcit learning notes
随机推荐
Snyk 依赖性安全漏洞扫描工具
在Rainbond中实现数据库结构自动化升级
Pytoch (VI) -- model tuning tricks
Ebpf cilium practice (2) - underlying network observability
OpenVSCode云端IDE加入Rainbond一体化开发体系
iptables 之 state模块(ftp服务练习)
opencv学习笔记一——读取图像的几种方法
2-3查找树
MES system is a necessary choice for enterprise production
Vulnerability recurrence fastjson deserialization
Caractéristiques de bisenet
MySQL introduction - crud Foundation (establishment of the prototype of the idea of adding, deleting, changing and searching)
The single value view in Splunk uses to replace numeric values with text
Open3D ISS关键点
Kotlin combines flatmap for filtering and zip merge operators
IP guard helps energy enterprises improve terminal anti disclosure measures to protect the security of confidential information
【Go ~ 0到1 】 第七天 获取时间戳,时间比较,时间格式转换,Sleep与定时器
一种适用于应用频繁测试下快速查看Pod的日志的方法(grep awk xargs kuberctl)
The use of generics and vararg variable parameters in kotlin
Practice of implementing cloud native Devops based on rainbow library app