dmath: init directory
This commit is contained in:
parent
afa80b0937
commit
84bf83a36b
7 changed files with 200 additions and 0 deletions
36
dmath/hcf.d
Normal file
36
dmath/hcf.d
Normal file
|
@ -0,0 +1,36 @@
|
|||
import std.conv : to;
|
||||
import std.stdio : write, writeln;
|
||||
|
||||
void
|
||||
main(string[] args)
|
||||
{
|
||||
int i, x, y;
|
||||
int[] xf, yf;
|
||||
|
||||
x = args[1].to!int();
|
||||
y = args[2].to!int();
|
||||
|
||||
xf = factorsOf(x);
|
||||
yf = factorsOf(y);
|
||||
for (i = 0; xf.length > i || yf.length > i; i++) {
|
||||
if (i < xf.length)
|
||||
write(xf[i]);
|
||||
write(" ");
|
||||
if (i < yf.length)
|
||||
write(yf[i]);
|
||||
writeln();
|
||||
}
|
||||
}
|
||||
|
||||
int[]
|
||||
factorsOf(int x)
|
||||
{
|
||||
int[] a;
|
||||
|
||||
foreach (int i; 1 .. x + 1) {
|
||||
if (x % i == 0)
|
||||
a ~= i;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue