当前位置:网站首页>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;
}
边栏推荐
- Opencv learning note 3 - image smoothing / denoising
- Domain specific language / DSL in kotlin
- Rainbond结合NeuVector实践容器安全管理
- [go ~ 0 to 1] obtain timestamp, time comparison, time format conversion, sleep and timer on the seventh day
- 数据中台落地实施之法
- IELTS review progress and method use [daily revision]
- Deit learning notes
- Snyk 依赖性安全漏洞扫描工具
- Installation and configuration of PLSQL
- Pvtv2--pyramid vision transformer V2 learning notes
猜你喜欢
![[untitled]](/img/b5/348b1d8b5d34cf10e715522b9871f2.png)
[untitled]

Splunk子查询模糊匹配csv中字段值为*

Virtual address space

Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms

使用SwinUnet训练自己的数据集

Input of mathematical formula of obsidan

National standard gb28181 protocol video platform easygbs adds streaming timeout configuration

在 Rainbond 中一键安装高可用 Nacos 集群

Xcit learning notes

Obsidan之数学公式的输入
随机推荐
机器人教育在动手实践中的真理
Practice of combining rook CEPH and rainbow, a cloud native storage solution
2-3查找樹
CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand
National standard gb28181 protocol video platform easygbs adds streaming timeout configuration
Vulnerability recurrence fastjson deserialization
使用 Nocalhost 开发 Rainbond 上的微服务应用
[untitled]
In go language, function is a type
[IELTS speaking] Anna's oral learning records Part3
数据中台落地实施之法
MES系統,是企業生產的必要選擇
Rainbow version 5.6 was released, adding a variety of installation methods and optimizing the topology operation experience
Opencv learning notes 1 -- several methods of reading images
The truth of robot education in hands-on practice
在Rainbond中实现数据库结构自动化升级
Réplication de vulnérabilité - désrialisation fastjson
Rainbow combines neuvector to practice container safety management
在Rainbond中一键部署高可用 EMQX 集群
GFS distributed file system