C语言模拟考|Proper Fraction
来源:互联网 发布:c语言编写驱动程序 编辑:程序博客网 时间:2024/05/16 18:16
Description
giving an integer N (2<=N<=20) and a real number M (0<M<=1), output all proper fractions whose numerator is less than N ,and denominator is equal to or less than N, and value is equal to or less than M.
Input
an integer N, a real number M in the type of double, in one line seperated by blank space.
Output
proper fractions, each occupies a line. The proper fractions with smaller denominators are in the front. Between two different fractions with same denominator, the one whose numerator is smaller comes first. There is a '\n' after the final fraction number.
Sample Input
6 0.7
Sample Output
1/21/32/31/41/52/53/51/6
#include <stdio.h>int gcd(int x, int y);int gcd(int x, int y) {while (x != y) {if (x > y) {x = x - y;}else {y = y - x;}}return x;}int main() {int n, i, j;double m;scanf("%d %lf",&n,&m);for (i = 1; i <= n; ++ i) {for (j = 1; j <= i; ++ j) {if (j*1.0/i > m) break;if (gcd(j, i) == 1) {printf("%d/%d\n",j,i);}}}}
1 0
- C语言模拟考|Proper Fraction
- proper fraction
- C语言模拟考|rectangles
- C语言模拟考|Counting
- C语言模拟考|lower cases
- C语言模拟考|Maximal Discount
- 考了C语言!
- C语言常考基本概念
- 明天就考C语言
- HDU 5912 Fraction 【模拟】
- HDU5912 Fraction(模拟)
- 模拟:Fraction HDU
- HDU 1112 The Proper Key DFS+模拟
- hdu1112 The Proper Key ----DFS+模拟
- hdu 5912 Fraction 模拟题
- hdoj 5912 Fraction(模拟)
- c语言,电梯模拟
- c语言模拟时钟
- dht11模块的学习
- 嵌入式驱动编写-第一个驱动程序
- 文件属性分析
- 高低压为什么不能共地的一个解释
- 项目版本不同导致Eclipse报错问题——关于在JDK1.7环境中,运行JDK1.8环境下编写的项目。
- C语言模拟考|Proper Fraction
- Python的垃圾回收
- 平面上的邮局
- 161105
- js this的应用场景
- xml,json,对象 之间的相互转换
- ListView中打造通用ViewHolder
- 懒汉式单例和饿汉式单例
- C#_将时间转换成字符串的几种方法