Please open the menu to show more

Thursday, August 3, 2017

Solution for the assignment (greatest common divisor) of 10 to 12 batch given on 3rd, August, 2017

This solution is implemented and provided by 
=> NEERAJ KUMAR MODANWAL
=> CSE
=> CSJM GOVT POLY AMBEDKARNAGAR




# save this class inside GCD.java file #

// inside this code we are calculating GCD (greatest common divisor)

import java.util.Scanner;

public class GCD {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter First Number : ");
// This Int type variable use for enter first number
int num1 = sc.nextInt();

System.out.print("Enter Second Number : ");
// This Int type variable use for enter second number
int num2 = sc.nextInt();

System.out.println("");
System.out.println("Maximum number which Divided Both Number : ");

// This Variable use for comparing value
int max = -1;

// This Loop use for find G.C.D.
for(int i=1;i<=num1;i++)
{

// If Statement Use for first number that how many number divided 
if( num1%i == 0)
{

// If Statement Use for Second number that how many number divided
if(num2%i == 0)
{
// This Statement Use for find max number which divided both number



if(i > max )
{
// And this number store in max variable
max = i;

}

}
}

}
System.out.println(max);

}
}

No comments:

Post a Comment