CODING:
import java.util.Scanner;
public class gcd {
public static void main(String[] args) {
int a,b,A=0,B=0,temp=0;
int[] aa=new int[100];
int[] bb=new int[100];
Scanner sc = new Scanner(System.in);
System.out.print("Enter Number Of A ");
a=sc.nextInt();
System.out.print("Enter Number Of B ");
b=sc.nextInt();
if(a>b){
temp=a;
a=b;
b=temp;
}
for(int i=1;i<=b/2;i++){
if(a%i==0 && a>=a/2){
aa[A]=i;
aa[A+1]=a/i;
A++;
}
if(b%i==0){
bb[B]=i;
bb[B+1]=b/i;
B++;
}
if(a%i==0 && b%i==0){
temp=i;
}
}
bb[B]=b;
for(int i=0;i<A;i++,A--){
System.out.println(aa[i]+"*"+bb[A]);
}
System.out.println("\n");
for(int i=0;i<=B;i++,B--){
System.out.println(bb[i]+"*"+bb[B]);
}
System.out.println("GCD number "+temp);
}
}
/*OUTPUT
Enter Number Of A 44
Enter Number Of B 88
1*44
2*22
4*11
1*88
2*44
4*22
8*11
GCD number 44*/
public class gcd {
public static void main(String[] args) {
int a,b,A=0,B=0,temp=0;
int[] aa=new int[100];
int[] bb=new int[100];
Scanner sc = new Scanner(System.in);
System.out.print("Enter Number Of A ");
a=sc.nextInt();
System.out.print("Enter Number Of B ");
b=sc.nextInt();
if(a>b){
temp=a;
a=b;
b=temp;
}
for(int i=1;i<=b/2;i++){
if(a%i==0 && a>=a/2){
aa[A]=i;
aa[A+1]=a/i;
A++;
}
if(b%i==0){
bb[B]=i;
bb[B+1]=b/i;
B++;
}
if(a%i==0 && b%i==0){
temp=i;
}
}
bb[B]=b;
for(int i=0;i<A;i++,A--){
System.out.println(aa[i]+"*"+bb[A]);
}
System.out.println("\n");
for(int i=0;i<=B;i++,B--){
System.out.println(bb[i]+"*"+bb[B]);
}
System.out.println("GCD number "+temp);
}
}
/*OUTPUT
Enter Number Of A 44
Enter Number Of B 88
1*44
2*22
4*11
1*88
2*44
4*22
8*11
GCD number 44*/
Comments
Post a Comment