程设作业(递归判断两个数互质)
来源:互联网 发布:java中权限控制框架 编辑:程序博客网 时间:2024/06/05 10:15
giving an integer N (2 <= N <= 20) and a real number M (0.5 < 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.7output:1/21/32/31/41/52/53/51/6
答:
#include<stdio.h>int IFhuzhi(int a, int b) { //a b互质当且仅当 b 与 a % b互质 if (a % b != 0) return IFhuzhi(b, a % b); else if (b == 1) return 1; else return 0;}int main(void) { int N; double M; scanf("%d %lf", &N, &M); int a, b; for (b = 2; b <= N; ++b) for (a = 1; a <= b; ++a) if (a * 1.0 / b <= M && IFhuzhi(b, a) == 1) printf("%d/%d\n", a, b); return 0;}
0 0
- 程设作业(递归判断两个数互质)
- 程设作业(合成矩形)
- 程设作业:模板
- 程设作业:MyString类
- 判断两个二叉树是否相同(c++递归实现)
- PKU-静态成员作业-程设hw03
- 程设作业:魔兽世界2:装备
- PKU-多态作业-程设hw04
- PKU-MyString类作业-程设hw04-MyString1.cpp(重现)
- PKU-MyInt和HugeInt作业-程设hw03
- PKU-MyString类作业-程设hw04-MyString1.cpp(继承)
- 判断两个数是否为素数的递归法
- 递归判断两个类是不是父子类关系
- 程设作业:文件操作作业 解题报告&弱弱的代码
- 多重循环+方法+递归(新手作业)
- 判断两个二叉树是否相等(仅结构) -- 递归和非递归实现
- 求两个数的最大公约数(作业)
- 判断两个时间差(Date)
- Android程序员学PHP开发(13)-简易计算器-PhpStorm
- String...和String[]区别
- 数据库对象命名参考
- zoj1163
- Android StringUtils
- 程设作业(递归判断两个数互质)
- 利用Jexl输出造型为Object实体类的某个变量属性值
- spring框架学习(五)注解
- springMVC+hibernate+oracle10g实现用户登陆
- Linux Top 命令解析
- MongoDB干货系列2-MongoDB执行计划分析详解(2)
- centos7下安装mysql
- 销售退货业务流程
- MySQL Group Replication HA with ProxySQL [主节点故障切换对应用无感知]