Write Java Source Code on Printing the Greatest Common Divisor or GCD in Recursion
Sample Output:Enter the base number: 100
Enter the power: 45
The GCD of 2 numbers is: 5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
| //java class public class GCD { public static int gcd( int num1, int num2) { if (num2 == 0 ) { return num1; } else { return gcd(num2, num1%num2); } } } //main class import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print( "Enter the base number: " ); int num1 = input.nextInt(); System.out.print( "Enter the power: " ); int num2 = input.nextInt(); GCD access = new GCD(); System.out.print( "The GCD of 2 numbers is: " + access.gcd(num1, num2)); } } |
Mohammad Ashraful Hasan Sobuj
ReplyDeleteMy Batch- 46th
My Department :CSE
My ID 201420656
public class SOBUJ
{
public static int sobuj(int num1, int num2)
{
if(num2 == 0)
{
return num1;
}
else
{
return sobuj(num2, num1%num2);
}
}
}
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the base number: ");
int num1 = input.nextInt();
System.out.print("Enter the power: ");
int num2 = input.nextInt();
SOBUJ access = new SOBUJ();
System.out.print("The SOBUJ of 2 numbers is: " + access.sobuj(num1, num2));
}
}
sultana razia khan
ReplyDeleteMy Batch- 46th
My Department :CSE
My ID 201420715
public class GCD
{
public static int gcd(int num1, int num2)
{
if(num2 == 0)
{
return num1;
}
else
{
return gcd(num2, num1%num2);
}
}
}
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the base number: ");
int num1 = input.nextInt();
System.out.print("Enter the power: ");
int num2 = input.nextInt();
GCD access = new GCD();
System.out.print("The GCD of 2 numbers is: " + access.gcd(num1, num2));
}
}
Sharmin Akter
ReplyDeleteMy Batch- 46th
My Department :CSE
My ID 201420769
public class MOUSUMI
{
public static int mousumi(int num1, int num2)
{
if(num2 == 0)
{
return num1;
}
else
{
return mousumi(num2, num1%num2);
}
}
}
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the base number: ");
int num1 = input.nextInt();
System.out.print("Enter the power: ");
int num2 = input.nextInt();
MOUSUMI access = new MOUSUMI();
System.out.print("The MOUSUMI of 2 numbers is: " + access.mousumi(num1, num2));
}
Name : Jalis mahmud
ReplyDeleteID : 201420762
Batch : 46th
public class jalis mahmud
{
public static int sobuj(int num3, int num4)
{
if(num4 == 0)
{
return num3;
}
else
{
return sobuj(num4, num1%num4);
}
}
}
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the base number: ");
int num3 = input.nextInt();
System.out.print("Enter the power: ");
int num4 = input.nextInt();
jalis mahmud access = new jalis mahmud();
System.out.print("The jalis mahmud of 4 numbers is: " + access.sobuj(num3, num4));
}
}
ID-201420406
ReplyDeleteBatch-46th
public class GCD
{
public static int gcd(int num1, int num2)
{
if(num2 == 0)
{
return num1;
}
else
{
return gcd(num2, num1%num2);
}
}
}
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the base number: ");
int num1 = input.nextInt();
System.out.print("Enter the power: ");
int num2 = input.nextInt();
GCD access = new GCD();
System.out.print("The GCD of 2 numbers is: " + access.gcd(num1, num2));
}
}
Name : Jalis mahmud
ReplyDeleteID : 201420763
Batch : 46th
public class Aliabat
{
public static int Aliabat(int num3, int num4)
{
if(num4 == 0)
{
return num3;
}
else
{
return Aliabat(num4, num1%num4);
}
}
}
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the base number: ");
int num3 = input.nextInt();
System.out.print("Enter the power: ");
int num4 = input.nextInt();
Aliabat access = new Aliabat();
System.out.print("The Dipika of 4 numbers is: " + access.Aliabat(num3, num4));
}
}