###### tags: `I2P(I)Hu2023` # 14040 - GCD > by schdoel ## Brief Given two integers, calculate their greatest common divisor. ## Solution You can make use of the euclidean algorithm, to implement the algorithm without using functions, while statement is a good way to go. ## Reference Code ```cpp= #include <stdio.h> int main(void){ int a, b; scanf("%d%d", &a, &b); while(a && b){ if(a >= b) a %= b; else b %= a; } if(a >= b) printf("%d\n", a); else printf("%d\n", b); return 0; } ```