Page 457 - CA_Blue( J )_Class10
P. 457
8 for(i=s;i>=1;i--)
9 {
10 if(a%i==0 && b%i==0) // Checking whether both the numbers are
//divisible by i
11 {
12 gcd=i;
13 break;
14 }
15 }
16 System.out.println("Greatest Common Divisor : " + gcd); //Displaying gcd
17 }
18
19 public static void main() //main() method
20 {
21 Scanner sc= new Scanner(System.in);
22 int m,n;
23 System.out.println("Enter two numbers ");
24 m=sc.nextInt();
25 n=sc.nextInt();
26 gcdmethod(m,n); // Method Invocation
27 } // Close of main()
28 } // Close of class
Output
Enter two numbers
18
24
Greatest Common Divisor : 6
Variable Description
NAME DATATYPE DESCRIPTION
m int Actual Parameter to store first number
n int Actual Parameter to store second number
a int Formal Parameter to store first number
b int Formal Parameter to store second number
i int Loop variable
gcd int Variable to store the Greatest Common Divisor
s int Variable to store smallest of the two numbers
455
Internal Assessment 455

