当前位置:网站首页>7-24 reduction of the simplest fraction (rolling Division)
7-24 reduction of the simplest fraction (rolling Division)
2022-07-03 14:14:00 【Big fish】
Fractions can be expressed as molecules / The form of denominator . Write a program , Ask the user to enter a score , Then it is reduced to the simplest fraction . The simplest fraction means that the numerator and denominator have no reducible components . Such as 6/12 Can be roughly divided into 1/2. When the numerator is greater than the denominator , It doesn't need to be expressed as an integer and a fraction , namely 11/8 still 11/8; And when the numerator and denominator are equal , Still expressed as 1/1 The fractional form of .
Input format :
Input gives a score in one line , Use a slash between the numerator and denominator / Separate , Such as :12/34 Express 34 Divided 12. Both numerator and denominator are positive integers ( It doesn't contain 0, If you don't know the definition of positive integers ).
Tips :
about C Language , stay scanf Add... To the format string of /, Give Way scanf To handle this slash .
about Python Language , use a,b=map(int, input().split('/')) This code handles the slash .
Output format :
Output the simplest fraction corresponding to this score in one line , The format is the same as that entered , That is, using molecules / The form of denominator represents fraction . Such as 5/6 Express 6 Divided 5.
sample input :
66/120
No blank lines at the end
sample output :
11/20
Use division by rotation :
#include<stdio.h>
int f(int a,int b){
int temp;
while(b!=0){
temp=a%b;
a=b;
b=temp;
}
return a;
}
int main(){
int a,b,n;
scanf("%d/%d",&a,&b);
n=f(a,b);
printf("%d/%d\n",a/n,b/n);
return 0;
}Violent solution :
#include<stdio.h>
int main(){
int a,b,i;
char c;
scanf("%d/%d",&a,&b);
i=a;
while(b%i!=0||a%i!=0){
i--;
}
printf("%d/%d\n",a/i,b/i);
return 0;
}
边栏推荐
- C language,%d% Difference between 2D%2d%02d
- Global event bus
- 7-11 calculation of residential water charges by sections
- JS Part 2
- 全文检索引擎Solr系列—–全文检索基本原理
- JS shift operators (< <,> > and > > >)
- 天图投资冲刺港股:资产管理规模249亿 投了小红书与奈雪
- Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
- js . Find the first palindrome string in the array
- 556. 下一个更大元素 III
猜你喜欢

消息订阅与发布

剑指 Offer 28. 对称的二叉树

7-8 overspeed judgment

JS Part III

jvm-运行时数据区

Uio-66-cooh loaded bendamostine | hydroxyapatite (HA) coated MIL-53 (FE) nanoparticles | baicalin loaded manganese based metal organic skeleton material

FPGA test method takes mentor tool as an example

Solution to failure or slow downloading of electron when electron uses electron builder to package

Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions

Exercise 9-1 time conversion
随机推荐
Fabric. JS document
Redis: redis data structure and key operation commands
“又土又穷”的草根高校,凭什么被称为“东北小清华”?
LNMP环境mail函数不能发送邮件解决
js 2023. String pair equal to the target string after connection
QT learning 20 standard dialog box in QT (middle)
虽然不一定最优秀,但一定是最努力的!
JVM垃圾回收机
好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录
x86汇编语言-从实模式到保护模式 笔记
Invalid Z-index problem
GRPC的四种数据流以及案例
Raft 协议
JS input number and standard digit number are compared. The problem of adding 0 to 0
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
QT learning 25 layout manager (4)
金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
【吉林大学】考研初试复试资料分享
JVM class loading