编号:1
C版本:
Java版本:
C版本:
#include <stdio.h>
long gcd(long a,long b){
long rem=0;
while(b!=0) {
rem=a%b;
a=b;
b=rem;
}
return a;
}
int main(){
long a=0,b=0;
scanf("%ld,%ld",&a,&b);
printf("The greatest common divisor of the two is : %ld",gcd(a,b));
return 0;
}
long gcd(long a,long b){
long rem=0;
while(b!=0) {
rem=a%b;
a=b;
b=rem;
}
return a;
}
int main(){
long a=0,b=0;
scanf("%ld,%ld",&a,&b);
printf("The greatest common divisor of the two is : %ld",gcd(a,b));
return 0;
}
Java版本:
package problem1;
import java.io.*;
public class Main {
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
long a = Integer.parseInt(reader.readLine());
long b = Integer.parseInt(reader.readLine());
System.out.println("The greatest common divisor of the two is "
+ gcd(a, b));
} catch (Exception e) {
System.out.println(e);
}
}
private static long gcd(long a, long b) {
while (b != 0) {
long rem = a % b;
a = b;
b = rem;
}
return a;
}
}
import java.io.*;
public class Main {
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
long a = Integer.parseInt(reader.readLine());
long b = Integer.parseInt(reader.readLine());
System.out.println("The greatest common divisor of the two is "
+ gcd(a, b));
} catch (Exception e) {
System.out.println(e);
}
}
private static long gcd(long a, long b) {
while (b != 0) {
long rem = a % b;
a = b;
b = rem;
}
return a;
}
}