diophantine solution printing improvements

This commit is contained in:
jacekpoz 2024-03-22 12:43:24 +01:00
parent 1081e52ad9
commit a4638192c6
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
7 changed files with 21 additions and 14 deletions

View file

@ -11,10 +11,11 @@ int main(int argc, char *argv[]) {
printf("gcd(a, b): %lu\n", gcd(atol(argv[1]), atol(argv[2])));
printf("factorial(a): %lu\n", factorial(atol(argv[1])));
Result *r = diophantine(atol(argv[1]), atol(argv[2]), atol(argv[3]));
printf("diophantine(a, b, c): ");
if (r == NULL)
printf("dupa\n");
printf("there's no solution\n");
else
printf("diophantine(a, b, c): %ld, %ld\n", r->n, r->m);
printf("%ld, %ld\n", r->n, r->m);
return 0;
}

View file

@ -16,9 +16,10 @@ begin
Put_Line("gcd(a, b):" & Natural'Image(gcdResult));
Put_Line("factorial(a):" & Natural'Image(factorialResult));
Put("diophantine(a, b, c): ");
if not diophantineResult.resultExists then
Put_Line("dupa");
Put_Line("there's no solution");
else
Put_Line("diophantine(a, b, c): " & Integer'Image(diophantineResult.n) & "," & Integer'Image(diophantineResult.m));
Put_Line(Integer'Image(diophantineResult.n) & "," & Integer'Image(diophantineResult.m));
end if;
end Main;

View file

@ -29,9 +29,10 @@ fn main() {
println!("gcd(a, b): {}", module.gcd(10, 5));
println!("factorial(a): {}", module.factorial(5));
let r = module.diophantine(1027, 712, 1);
print!("diophantine(a, b, c): ");
if r.is_none() {
println!("dupa");
println!("there's no solution");
} else {
println!("diophantine(a, b, c): {}, {}", r.unwrap().0, r.unwrap().1);
println!("{}, {}", r.unwrap().0, r.unwrap().1);
}
}

View file

@ -12,10 +12,11 @@ int main(int argc, char *argv[]) {
printf("gcd(a, b): %u\n", gcd(atol(argv[1]), atol(argv[2])));
printf("factorial(a): %u\n", factorial(atol(argv[1])));
Result r = diophantine(atol(argv[1]), atol(argv[2]), atol(argv[3]));
printf("diophantine(a, b, c): ");
if (!r.resultExists)
printf("dupa\n");
printf("there's no solution\n");
else
printf("diophantine(a, b, c): %d, %d\n", r.n, r.m);
printf("%d, %d\n", r.n, r.m);
return 0;
}

View file

@ -40,9 +40,10 @@ begin
Put_Line("gcd(a, b):" & Natural'Image(gcdResult));
Put_Line("factorial(a):" & Natural'Image(factorialResult));
Put("diophantine(a, b, c): ");
if not diophantineResult.resultExists then
Put_Line("dupa");
Put_Line("there's no solution");
else
Put_Line("diophantine(a, b, c): " & Integer'Image(diophantineResult.n) & "," & Integer'Image(diophantineResult.m));
Put_Line(Integer'Image(diophantineResult.n) & "," & Integer'Image(diophantineResult.m));
end if;
end Main;

View file

@ -18,10 +18,11 @@ fn main() {
println!("gcd(a, b): {}", gcd(10, 5));
println!("factorial(a): {}", factorial(5));
let r = diophantine(1027, 712, 1);
print!("diophantine(a, b, c): ");
if r.resultExists == 0 {
println!("dupa");
println!("there's no solution");
} else {
println!("diophantine(a, b, c): {}, {}", r.n, r.m);
println!("{}, {}", r.n, r.m);
}
}
}

View file

@ -12,10 +12,11 @@ int main(int argc, char *argv[]) {
printf("gcd(a, b): %u\n", gcd(atol(argv[1]), atol(argv[2])));
printf("factorial(a): %u\n", factorial(atol(argv[1])));
Result r = diophantine(atol(argv[1]), atol(argv[2]), atol(argv[3]));
printf("diophantine(a, b, c): ");
if (!r.resultExists)
printf("dupa\n");
printf("there's no solution\n");
else
printf("diophantine(a, b, c): %d, %d\n", r.n, r.m);
printf("%d, %d\n", r.n, r.m);
return 0;
}