# calculation for lowest common denominator ratioRSS

## 4 replies

Last post Oct 17, 2008 02:04 AM by TATWORTH

• mike123

Member

20 Points

686 Posts

### calculation for lowest common denominator ratio

Hi,

I have a function I am trying to code as below.  Basically if I pass "100" as free signups and "1000" as clicks, I want to get a value of   "1:10"

could anyone help me out on this one ?  I think its more complex than it appears..

Thanks very much!

mike123

Function showRatio(ByVal freeSignups As Integer, ByVal clicks As Integer) As String

showratio =

End Function

• agarwal.rahu...

Member

40 Points

15 Posts

### Re: calculation for lowest common denominator ratio

migrate the code snippet to c#. it's easier than it seems to be :)

int main()
{
int a, b, d, min;

cout << "Enter two numbers: ";
cin >> a >> b;

min = a > b ? b : a;

for(d = 2; d<min; d++
if(((a%d)==0&& ((b%d)==0))
break;
if(d==min) {
cout << "No common denominators\n";
return 0;
}
cout << "The lowest common denominator is " << d << ".\n";

return 0;
}

• kutind

Member

306 Points

121 Posts

### Re: calculation for lowest common denominator ratio

Private Function showRatio(ByVal freeSignups As Integer, ByVal clicks As Integer) As String

Dim gcd As Integer = greatestCommonDivisor(freeSignups, clicks)
showRatio = (freeSignups / gcd) & ":" & (clicks / gcd)

End Function

Public Shared Function greatestCommonDivisor(ByVal a As Integer, ByVal b As Integer) As Integer

Dim c As Integer

While (b > 0)
c = b
b = a Mod b
a = c

End While
Return a

End Function

• mike123

Member

20 Points

686 Posts

thx!
• TATWORTH

All-Star

44561 Points

13497 Posts

MVP