Browse Source

added simple algorithm for getting the kgV

remotes/origin/kgV
cxnnqr 11 months ago
parent
commit
66f28def92
  1. 18
      src/kgV/kgV.c

18
src/kgV/kgV.c

@ -1,3 +1,19 @@
#include <stdio.h> #include <stdio.h>
int kgV(int a, int b);
int ggT(int a, int b){
// handles the zero cases
if(a == 0) return b;
if(b == 0) return a;
// Euclidean algorithm with modulo for getting the ggT
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
int kgV(int a, int b){
return a*b/ ggT(a, b);
}
Loading…
Cancel
Save