当前位置:网站首页>Noi OJ 1.3 05: floating point numeric C language for calculating fractions
Noi OJ 1.3 05: floating point numeric C language for calculating fractions
2022-06-23 10:29:00 【chd44】
describe
Two integers a and b As numerator and denominator respectively , Existing score a/b , Find its floating-point value ( Double precision floating point , After decimal point 9 position )
Input
Enter only one line , Includes two integers a and b(b Not for 0)
Output
The output is only one line , fraction a/b The floating-point value of ( Double precision floating point , After decimal point 9 position )
There are two solutions to the problem
The first is to set the input number to double The type of , So the number after rounding out will also be double Type of ( as follows )
#include<stdio.h>
int main(){
double a,b;
scanf("%lf %lf",&a,&b);
printf("%.9lf",a/b);
return 0;
}The second can be seen as a cast
#include<stdio.h>
int main(){
int a,b;
scanf("%d %d",&a,&b);
double c=a*1.0/b;
printf("%.9lf",c);
return 0;
}notes : there a must *1.0, If direct a/b Words , Both are int The integer of , So the number that comes out of the division must be an integer , But if we *1.0, So we give integers a new type , You can go to double Divide by ( At this time a*1.0 Can be seen as a new double Number of types ).
边栏推荐
- STM32F1与STM32CubeIDE编程实例-红外寻迹传感器驱动
- Mysql-03. Experience of SQL optimization in work
- 2021-05-11抽象类
- Tencent tangdaosheng: practice "science and technology for the good" and promote sustainable social value innovation
- The era of copilot free is over! The official version is 67 yuan / month, and the student party and the defenders of popular open source projects can prostitute for nothing
- Implementing Domain Driven Design - using ABP framework - General guidelines
- 马斯克 18 岁儿子请愿改名,欲断绝父子关系
- MySQL-02. Understanding of indexes at work
- Pycharm installation tutorial, super detailed
- Five SQL functions for operation date that must be known in SQL tutorial
猜你喜欢

Build a QQ robot to wake up your girlfriend

sql根据比较日期新建字段

Different methods of PivotTable in SQL tutorial

RT thread add MSH command

AI芯片技术-2022年

Data structures and differences between MySQL InnoDB engine and MyISAM

Is IPv6 faster than IPv4?

卧槽,最惊艳的论文神器!

SQL create a new field based on the comparison date

SQL教程之SQL 中数据透视表的不同方法
随机推荐
2021-05-11static关键字
NOI OJ 1.3 15:苹果和虫子 C语言
NOI OJ 1.3 11:计算浮点数相除的余数 C语言
SQL教程之SQL 中数据透视表的不同方法
同花顺推荐么?手机开户安全么?
安装typescript环境并开启VSCode自动监视编译ts文件为js文件
Bugs encountered in Oracle
2021-04-16方法重载 传参
【第23天】给定一个长度为 n 的数组,将元素 X 插入数组指定的位置 | 数组插入操作4
2021-04-16 method overload parameter transfer
Large homework collection
数学分析_笔记_第2章:实数与复数
[day 23] given an array of length N, insert element x into the position specified by the array | array insertion operation 4
Mysql-03.工作中对SQL优化的心得体会
Description of directory files of TLBB series of Tianlong Babu - netbill server [ultra detailed]
2021-05-12 interface definition and Implementation
The era of copilot free is over! The official version is 67 yuan / month, and the student party and the defenders of popular open source projects can prostitute for nothing
sql编写问题,求出当月和上月的环比值
几款实用软件分享
天龙八部TLBB系列 - 网单服务端各目录文件说明【超详细】