当前位置:网站首页>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 ).
边栏推荐
猜你喜欢
随机推荐
数学分析_笔记_第2章:实数与复数
汇编语言中断及外部设备操作篇--06
2021-05-12内部类
数值计算方法
Spring recruitment interview experience summary (technical post)
同花顺推荐么?手机开户安全么?
How to pass values to onclick events in thymeleaf
Year end answer sheet! Tencent cloud intelligent comprehensive strength ranks first in China!
NOI OJ 1.3 09:与圆相关的计算 C语言
个人博客系统毕业设计开题报告
NOI OJ 1.4 01:判断数正负 C语言
web技术分享| 【高德地图】实现自定义的轨迹回放
Musk's 18-year-old son petitioned to change his name to sever the father son relationship
SQL create a new field based on the comparison date
Mathematical analysis_ Notes_ Chapter 2: real and plural numbers
同花顺是炒股的么?在线开户安全么?
Lu Qi invests in quantum computing for the first time
太无奈!微软停售 AI 情绪识别等技术,直言:“法律跟不上 AI 的发展”
一个优秀速开发框架是什么样的?
基于SqlSugar的开发框架循序渐进介绍(9)-- 结合Winform控件实现字段的权限控制









