repl.it
C

No description

fork
loading
Files
  • main.c
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>

int gcd_recursive(int a, int b){
	if(b == 0){
		return a;
	}
	else{
		return gcd_recursive(b, a%b);
	}
}

void swap(int *a, int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd_iterative(int a, int b){
	int tmp;
	while(b != 0){
		a %= b;
		swap(&a, &b);
	}
	return a;
}

int main(){
	printf("%d", gcd_iterative(2, 3));

	return 0;
}