当前位置:网站首页>NOI OJ 1.3 05:计算分数的浮点数值 C语言
NOI OJ 1.3 05:计算分数的浮点数值 C语言
2022-06-23 10:12:00 【chd44】
描述
两个整数a和b分别作为分子和分母,既分数 a/b ,求它的浮点数值(双精度浮点数,保留小数点后9位)
输入
输入仅一行,包括两个整数a和b(b不为0)
输出
输出也仅一行,分数 a/b 的浮点数值(双精度浮点数,保留小数点后9位)
该题有两种解法
第一种是把输入的数就设置为double的类型,这样整出后得到的数也会是double类型的(如下)
#include<stdio.h>
int main(){
double a,b;
scanf("%lf %lf",&a,&b);
printf("%.9lf",a/b);
return 0;
}第二种可以看作是强制类型转换
#include<stdio.h>
int main(){
int a,b;
scanf("%d %d",&a,&b);
double c=a*1.0/b;
printf("%.9lf",c);
return 0;
}注:这里的 a 必须 *1.0,如果直接a/b的话,两者都为int的整数,所以整除出来的数必为整数,但是如果我们 *1.0,就把整数赋予成新的类型了,就可以在double的范围进行整除(此时把a*1.0可以看成一个新的具有double类型的数)。
边栏推荐
- 2021-05-07封装 继承 super this
- 2021-04-16 array
- oracle中遇到的bug
- I have been promoted. How can I get along with my former colleagues at the same level?
- NFTs、Web3和元宇宙对数字营销意味着什么?
- Numerical calculation method
- Bioinformatics | effective drug target correlation prediction based on interacting neural network
- 几款实用软件分享
- What is a good quick development framework like?
- 文件IO(1)
猜你喜欢

Go unit test

炫酷相册代码,祝对象生日快乐!

解决audio自动播放无效问题

J. Med. Chem. | Release: a new drug design model for deep learning based on target structure

Comic | code review is driving me crazy!

数学分析_笔记_第2章:实数与复数

Copilot免费时代结束!正式版67元/月,学生党和热门开源项目维护者可白嫖

谷贱伤农,薪贱伤码农!

陆奇首次出手投资量子计算

Bioinformatics | effective drug target correlation prediction based on interacting neural network
随机推荐
2021-04-12 链表第一次实现!!!
NiO example
2021-04-16 recursion
高性能算力中心 — NVMe/NVMe-oF — NVMe-oF Overview
2022高考季征文获奖名单公布
2021-05-11 instanceof and type conversion
AI system frontier dynamics issue 38: Google has abandoned tensorflow?; Four GPU parallel strategies for training large models; Father of llvm: modular design determines AI future
High performance computing center Infiniband overview
搭建一个点歌QQ机器人,另外还能看美女
sql根据比较日期新建字段
2021-05-11抽象类
Go string comparison
同花顺推荐么?手机开户安全么?
135,137,138,445禁用导致无法远程连接数据库
Unity技术手册 - 形状(Shape)子模块 - Sprite、SpriteRenderer及生命周期内速度(Velocity over Lifetime)
2021-05-10 method rewrite polymorphism considerations
利用华为云ECS服务器搭建安防视频监控平台
2021-05-12 internal class
JS教程之 什么是 JSX?为什么我们需要它?
Bioinformatics | effective drug target correlation prediction based on interacting neural network