Data Structures and Algorithms Discussion Board
September 02, 2010, 08:44:31 PM *
Welcome, Guest. Please login or register.
Login with username, password and session length
News: Looking for a reliable webhosting provider? Read HostGator review to find 7 arguments in support of HostGator.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: iterative, stack based method [Urgent]  (Read 3776 times)
zaini
Guest
« on: March 17, 2009, 08:22:30 AM »

Given two positive integers i and j, the greatest common divisor of i and j written gcd
(i, j) is the largest integer k such that (i % k = 0) and (j % k = 0).
Develop an iterative, stack based method that returns the greatest common divisor of
i and j.
Here is the method specification:
/**
* Finds the greatest common divisor of two given positive integers
*
* @param i – one of the given positive integers.
* @param j – the other given positive integer.
*
* @return the greatest common divisor of iand j.
*
* @throws IllegalArgumentException – if either i or j is not a positive integer.
*
*/
public static int gcd (int i, int j)
Test your method with a main method that reads in two positive integers and outputs their greatest common divisor.
Sample Input – Output:
Please enter two positive integers, separated by a space (or *** to quit): 20 40
The greatest common divisor of 20 and 40 is 20.
Please enter two positive integers, separated by a space (or *** to quit): ***



help me..... and 10Q
« Last Edit: March 17, 2009, 08:24:05 AM by zaini » Logged
Denis
Newbie
*

Rating: 0
Offline Offline

Posts: 21


« Reply #1 on: March 17, 2009, 10:00:52 AM »

What have you done yet? It's better to start with writing GCD algorithm using recursion. Then it can be transormed into a stack-based iteration.
Logged
suguneswari
Newbie
*

Rating: 0
Offline Offline

Posts: 1


« Reply #2 on: March 25, 2009, 12:33:47 PM »

Hi Zaini..

Better you do it your self than begging for others help!!
Don't be so selfish, you will not learn anything
See me at my room at 19th floor this thursday. Sad

Logged
izzammil
Newbie
*

Rating: 0
Offline Offline

Posts: 1


« Reply #3 on: March 25, 2009, 08:43:46 PM »

hi zaini
would u help me to solve the stack program that u have post..
can u give me the program so that i can check it with my own program..
because i have the problem with it..
thanks..
Logged
Pages: [1]
  Print  
 
Jump to:  

 
Partners Ads        debt consolidation advice and help