当前位置:网站首页>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;
}
边栏推荐
- CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand
- 使用SwinUnet训练自己的数据集
- Openjudge noi 2.1 1752: chicken and rabbit in the same cage
- Opencv learning note 3 - image smoothing / denoising
- 字符串操作
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
- opencv学习笔记五——梯度计算/边缘检测
- SSM 整合
- Open3d ISS key points
- Basic use of CTF web shrink template injection nmap
猜你喜欢
Réplication de vulnérabilité - désrialisation fastjson
Obsidan之数学公式的输入
Golang 编译约束/条件编译 ( // +build <tags> )
In go language, function is a type
Merge sort and non comparison sort
AVL平衡二叉搜索树
Interpreting the practical application of maker thinking and mathematics curriculum
OpenVSCode云端IDE加入Rainbond一体化开发体系
探索STEAM艺术设计中的创造力
解读创客思维与数学课程的实际运用
随机推荐
One click deployment of highly available emqx clusters in rainbow
rsync远程同步
Battery and motor technology have received great attention, but electric control technology is rarely mentioned?
GFS distributed file system
Detailed explanation of apply, also, let, run functions and principle analysis of internal source code in kotlin
Rsync remote synchronization
[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)
使用 Nocalhost 开发 Rainbond 上的微服务应用
饥荒云服管理脚本
SSM 整合
Learn how to compile basic components of rainbow from the source code
Offer harvester: add and sum two long string numbers (classic interview algorithm question)
DeiT学习笔记
The field value in Splunk subquery fuzzy matching CSV is*
如何理解分布式架构和微服务架构呢
Splunk子查询模糊匹配csv中字段值为*
发挥创客教育空间的广泛实用性
Rainbond结合NeuVector实践容器安全管理
使用BiSeNet实现自己的数据集
Interpreting the practical application of maker thinking and mathematics curriculum