c/c++训练(1)最大公约数与最小公倍数:输入两个整数,求它们的最大公约数与最小公倍数。
输入
输入两个整数,两个整数之间用空格分开。
输出
第一行输出最大公约数;
第二行输出最小公倍数。
example input
64 48
example output
16
192
代码如下:
import java.util.*; class number{ private int x; private int y; private int x1; private int y1; number(int a, int b){ x = a; y = b; x1 = a; y1 = b; } int com_fac(){ int t; int r; if (x < y){ t = x; x = y; y = t; } while(y != 0){ r = x % y; x = y; y = r; } return x; } int com_mul(){ return x1 * y1 / x; } } public class main{ public static void main(string args[]){ scanner input = new scanner(system.in); int x = input.nextint(); int y = input.nextint(); number num = new number(x, y); system.out.println(num.com_fac()); system.out.println(num.com_mul()); input.close(); } }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/606464.html