Thursday, March 4, 2010

Gcd_Algorithm

public class Gcd_Algorithm
{
//Method Iterator for Great Common Divisor
public static long iteration (long a, long b)
{
int gcd = 1;
int k = 1;

while (k <= a && k <= b)
{
if (a % k == 0 && b % k == 0)
gcd = k;
k++;
}

System.out.print("\nGreat Common Divisor in iteration method : " + gcd);
return gcd;
}








//Method Recursive
public static long recursion (long a, long b)
{
long gcd = 0;
long r = 0;

a = Math.abs (a);
b = Math.abs (b);
if (b == 0)
{
gcd = a; //if n == 0, then m = gcd
System.out.println ("\nGreat Common Divisor in recursive method : " + gcd);
}
else
{
gcd = recursion(b, a % b); //invoke recursive method, and return value n
}

return gcd;
}
}






import java.util.*;
public class Main
{
public static void main (String [] args)
{
Gcd_Algorithm gcd = new Gcd_Algorithm();

Scanner myscanner = new Scanner (System.in);
System.out.print ("Please enter value of a:");
long a = myscanner.nextInt(); //input m value

System.out.print ("Please enter value of b:");
long b = myscanner.nextInt(); //input n value

gcd.iteration(a, b); //invoke to iteration method
gcd.recursion(a, b); //invoke to recursion method
}
}
OUTPUT
--------------------Configuration: --------------------
Please enter value of a:3
Please enter value of b:5

Great Common Divisor in iteration method : 1
Great Common Divisor in recursive method : 1

Process completed.

1 comment:

  1. GREAT DEVELOPMENT GOALS ON ONLINE FUNDING ACCOUNTS. (3min read.)
    CRYPTOCURRENCY (BITCOIN) underhanded agency. The world's interesting array on financial change you wouldn't ever want to regret missing out on. Here is a global focus fully immersed to a degree that the subject in question Is an highly profitable finance worthwhile experience on merits. The organisation Constructing a long focus on funding your cryptocurrency(bitcoin) wallet with an enormous amounts of coins, including PAYPAL ACCOUNT, ONLINE BANK ACCOUNTS, ATM, and CREDIT CARD LOADING/CREDIT CARD DEPT CLEARANCE. Up a world of unimagined decentralized possibilities, where more online banking funds on value can be built, transferred, and managed with greater ease and transparency via Hacking.
    Being a victim of CRYPTOCURRENCY(bitcoin) Funds Mishap prompt our effort on finance cyber scandal focus (CSF). And the most interesting, Bitcoin Wallet Hack Rectification (BWHR), Bitcoin loading, PayPal loading, credit cards/ATM hack.
    Firstly,⚠warning!
    With money making, scam is a pretty common occurence today. Consumers have to be on a watch at any atrempt on financial fraud. That includes an ultimate addition of insult to injury. Be wary of forgeries who target victim of previous con, luring you in with bogus promises and you can even be charge for actions you could do on your own.
    This is a life time transformation with the professionals."
    You been trying so hard to meet with the real deal and changing your financial status to a massive ultimate crypto/dollar bill here is where your search ends. There is never a pleasure in been poor.
    As a strong and established personnel of cryptocurrency (bitcoin), PayPal, credit card user, in the terms of solid community, we strive to continue our mission on helping Individuals who are facing various cyber problems mostly the bitcoin hack swindles. Good news comes rare and it's left for us to whether cherish such glittering ounce of it like a priceless diamond or the otherwise.
    As part of our core mission and value to fix a dysfunctional bitcoin wallet accounts back to it normal stability and increasingly loading different accounts with huge funds via a dominant online crocked cyber tech algorithms. Taking a weighty focus on bitcoin hacks, For instance, wallet account facing problems which incudes.
    ▪Slack hacking bots,
    Fradulent bitcoin minning through brokers
    ▪Wallet hack,
    ▪Bitcoin minning pool and exchage hacking,
    ▪Changing wallet addresses
    ▪Cryptocurrency theft,
    ▪Freeze mining on crptocurrency.
    Here you are been given a chance to recover what you thought you lost and earnestly making a lot of funds via this highly classified information. This is a global information that navigates a newbie to a prominent encounter. We treat every request with patience and outmost confidence. Basically, hacking requires patience and no funds related successful hack goes lesser than 16 hours. The bottomline is we make a purposeful use of the time in lenience to attain a positive result to our clients.
    For our prominent services like Paypal funds loading, credit card dept clearance, credit card loading, website hack, social media hack, and one of the most important is loading up an empty online bank account with huge funds according to the account's capacity, you will all find your deepest longings to be reviewed. It's always like a dream.
     The job with the Globalhacks will be a sudden bursts of complete transformative joy and this is reality to your dreams.
    For more solid info and help,
    Contact:
    Cryptobase.hack(at)protonmail(.)com
    Globalhacktech(at)protonmail(.)com for proficient services.
    AndrewHay©️LLC 2019

    ReplyDelete