当前位置:网站首页>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 ).
边栏推荐
猜你喜欢

安装typescript环境并开启VSCode自动监视编译ts文件为js文件

File IO (1)

oracle中遇到的bug

Build the information and innovation industry ecology, and make mobile cloud based on the whole stack of independent innovation

Confessing with Snake games (with source code)

Different methods of PivotTable in SQL tutorial

RT-Thread 添加 msh 命令

JVM easy start-02

Unity技术手册 - 生命周期LifetimebyEmitterSpeed-周期内颜色ColorOverLifetime-速度颜色ColorBySpeed

Musk's 18-year-old son petitioned to change his name to sever the father son relationship
随机推荐
Bugs encountered in Oracle
Too helpless! Microsoft stopped selling AI emotion recognition and other technologies, saying frankly: "the law can not keep up with the development of AI"
Stm32f1 and stm32subeide programming example - infrared tracking sensor driver
MySQL-02.工作中对索引的理解
[day 23] given an array of length N, insert element x into the position specified by the array | array insertion operation 4
同花顺是炒股的么?在线开户安全么?
Year end answer sheet! Tencent cloud intelligent comprehensive strength ranks first in China!
Pycharm installation tutorial, super detailed
大作业合集
Implementing Domain Driven Design - using ABP framework - General guidelines
文献综述怎么写 ,一直没头绪写不出来怎么办?
Large homework collection
NOI OJ 1.3 17:计算三角形面积 C语言
MySQL-01. Summary of database optimization and explain field knowledge in work
2021-05-11 abstract class
Five SQL functions for operation date that must be known in SQL tutorial
2021-05-07封装 继承 super this
2021-04-27 classes and objects
Personal blog system graduation project opening report
Google Earth Engine(GEE)——用不同方法计算slope对比案例分析