5 May 2011 7:12 AM
Subject: Re: [algogeeks] Divisibility by five
b=n*0.2;
if((b-floor(b))==0)
print " number is divisible by 5";
else
print " number is not divisible by 5";
From: Umer Farooq
To: algogeeks@googlegroups.com
Sent: Tu
1000-floor(1000) gives 0
therefore n is divisible by 5
From: ADITYA KUMAR
To: algogeeks@googlegroups.com
Sent: Thursday, 5 May 2011 7:30 AM
Subject: Re: [algogeeks] Divisibility by five
anshu sols is best
@venkat what if b=1000
On Thu, May 5, 2011 at 7:12 AM
t; *From:* Umer Farooq
> *To:* algogeeks@googlegroups.com
> *Sent:* Tuesday, 3 May 2011 10:27 AM
> *Subject:* Re: [algogeeks] Divisibility by five
>
> public static isDivisibleByFive(int input)
> {
> String str_input = String.valueof(input); // convert initial int
b=n*0.2;
if((b-floor(b))==0)
print " number is divisible by 5";
else
print " number is not divisible by 5";
From: Umer Farooq
To: algogeeks@googlegroups.com
Sent: Tuesday, 3 May 2011 10:27 AM
Subject: Re: [algogeeks] Divisibility by
public static isDivisibleByFive(int input)
{
String str_input = String.valueof(input); // convert initial int to string.
if ((str_input.charat(str_input.length()-1) == '5') ||
(str_input.charat(str_input.length()-1) == '0') // check if the last
character is 0 or 5
return true;
return false;
}
Given an integer n, give an O(log n) algorithm to determine if n is
divisible by 5 without using division or mod.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe