Add student example inputs
This commit is contained in:
43
examples/gcd/gcd.mc
Normal file
43
examples/gcd/gcd.mc
Normal file
@@ -0,0 +1,43 @@
|
||||
/* calulcate modulo */
|
||||
int mod(int a, int b){
|
||||
return a-(a/b*b);
|
||||
}
|
||||
|
||||
/* calulate greatest common divisor */
|
||||
int gcd(int x, int y){
|
||||
int c;
|
||||
if (x < 0){
|
||||
x = -x;
|
||||
}
|
||||
|
||||
if (y < 0){
|
||||
y = -y;
|
||||
}
|
||||
|
||||
while (y != 0) {
|
||||
c = mod(x, y);
|
||||
x = y;
|
||||
y = c;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a;
|
||||
int b;
|
||||
|
||||
print("Please enter the first number: ");
|
||||
print_nl();
|
||||
a = read_int();
|
||||
print("Please enter the second number: ");
|
||||
print_nl();
|
||||
b = read_int();
|
||||
|
||||
int res = gcd(a,b);
|
||||
|
||||
print("The greatest common divisor is: ");
|
||||
print_int(res);
|
||||
print_nl();
|
||||
|
||||
return 0;
|
||||
}
|
2
examples/gcd/gcd.stdin.txt
Normal file
2
examples/gcd/gcd.stdin.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
10
|
||||
15
|
3
examples/gcd/gcd.stdout.txt
Normal file
3
examples/gcd/gcd.stdout.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
Please enter the first number:
|
||||
Please enter the second number:
|
||||
The greatest common divisor is: 5
|
Reference in New Issue
Block a user