Han Ruam Mak
Processing Code
int gcd(int x, int y) {if(x == 0) {
return y;
}
if(y == 0) {
return x;
}
if(x > y) {
return gcd(y, x%y);
}
else {
return gcd(x, y%x);
}
}
void setup() {
println(gcd(5, 10));
}
เทียบกับในการออกแบบภาษาจาวา โดยใช้โปรแกรม Terminal
class GCD{
public static int gcd(int x, int y) {
if(x == 0) {
return y;
}
if(y == 0) {
return x;
}
if(x > y) {
return gcd(y, x%y);
}
else {
return gcd(x, y%x);
}
}
public static void main(String [] arg) {
System.out.println(gcd(5,90));
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น