@all : doesnt sudhir's solution seem to work??
@sudhir: can u explain yr logic?
On Wed, Sep 21, 2011 at 8:31 AM, annarao kataru kataruanna...@gmail.comwrote:
can u explain the logic behind this
thanks in advance
--
You received this message because you are subscribed to the Google
can u explain the logic behind this
thanks in advance
--
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 from this group, send email to
*
*
*#include fstream
#include iostream
using namespace std;
bool flag=false;
void check(int i)
{
int sum=0;
char n[5];
itoa(i,n,10);
for(int j=0;j5 n[j] != '\0';j++)
{
char p = n[j];
sum += atoi(p);
}
if(sum==3 || sum==6 || sum==9)
flag = true;
else if(sum9)
check(sum);
}
void main()
{
int i;
@ankit: not the last digit..!!
it will be (last digit -3) or (last digit -3-3) whichever is positive..
:)
On 7/31/11, Ankit Minglani ankit.mingl...@gmail.com wrote:
yeah if it was a divisibility test then the question would have been too
trivial ..
the last digit after doing itoa will be the
Hi,
we can show that
(x/3) = (x/2) - (x/4) + (x/8) - (x/16) + infinity
Proof:
let s1 = (x/2)+(x/8)+(x/32)+...infinity = (x/2)/(1-(1/4)) [Geometric
Progression , common Ratio(r) = 1/4]
s2 = (x/4)+(x/16)+(x/64)+...infinity = (x/4)/(1-(1/4)) [Geometric
Progression , common Ratio(r) =
yeah if it was a divisibility test then the question would have been too
trivial ..
the last digit after doing itoa will be the remainder .
On Sat, Jul 30, 2011 at 11:52 AM, nivedita arora
vivaciousnived...@gmail.com wrote:
i think solution of ankit is right !
sorry even i forgot tht que ws
Single bit shift...
int divide(int n)
{
n-=1;
n=1;
return n;
}
On 7/30/11, tech rascal techrascal...@gmail.com wrote:
hw will u get the ans on repeated subtraction from the sum of the digits??
I mean if I hv 2 divide 27 by 3 thn first I'll find sum of the digits
i.e, 2+7=9
then I'll
@Samm : Im not able to understand ur logic...im not getting the correct
ans...can u explain the working taking n as 7?
On Sat, Jul 30, 2011 at 12:25 PM, SAMM somnath.nit...@gmail.com wrote:
Single bit shift...
int divide(int n)
{
n-=1;
n=1;
return n;
}
On 7/30/11, tech rascal
#includestdio.h
#includestdlib.h
#includeconio.h
#includestring.h
#includemath.h
int multiply(int a,int b)
{
int i;
int temp=a;
printf(\na=%d b=%d\n,a,b);
for(i=1;ib;i++)
a+=temp;
printf(\nfinal a = %d,a);
return(a);
}
void main ()
{
int x,rem,quo=0,i,j;
I think the whole point and advantage of using itoa is to make the
code suitable for larger integer inputs..
eg: if i/p is: 32765 , itoa gives 32765, we take each sum=3+2+7+6+5=
23 and then use repeated subtraction...
Repeated subtraction on 2 digit no. is much faster than on 5 digit one..!!
let the number be num
so code is this
int ans=0;
while(num=3)
{
num=num-3;
ans++;
}
No need to use itoa. This is simple division algo based on subtraction.
On Sat, Jul 30, 2011 at 2:09 PM, Ankit Minglani ankit.mingl...@gmail.comwrote:
#includestdio.h
#includestdlib.h
The objective is to divide the number by 3 and not just check for it's
divisibility.
Adding the digits using itoa() and then repeated subtraction will check for
it's divisibility by 3 and not give us the quotient.
To get that you will have to carry out repeated subtraction on the number
anyway.
@roopam : i got the question all wrong. . .
On Sat, Jul 30, 2011 at 10:01 PM, Roopam Poddar mailroo...@gmail.comwrote:
The objective is to divide the number by 3 and not just check for it's
divisibility.
Adding the digits using itoa() and then repeated subtraction will check for
it's
@roopam: Thats what i am saying... the function itoa only gives you
the remainder, it doesnt provide quotient..we need to do repeated
subtraction for that...
On 7/30/11, Ankur Khurana ankur.kkhur...@gmail.com wrote:
@roopam : i got the question all wrong. . .
On Sat, Jul 30, 2011 at 10:01
ur expression forms 4/8=1/2 and not 1/3...
On Sat, Jul 30, 2011 at 3:18 AM, Amit amitbaranwa...@gmail.com wrote:
well,well,well...
a=x1;
b=x2;
c=(a+b)1;
d=x3;
x=c+d;
actually i used the fact- 1/3 = 3/9 = ((1/2)+(1/4))/2 + 1/8
On Jul 30, 1:37 am, nivedita arora
int divideby3 (int num)
{
int sum = 0;
while (num 3) {
sum += num 2;
num = (num 2) + (num 3);
}
if (num == 3) ++sum;
return sum;
}
Thanks Regards...*
รυ∂んเя мเรんяค*
--
You received this message because you are subscribed to the Google Groups
Algorithm
shift the number to left two times and subtract once... I.e.
Int x=num;
x=x2;
x-=num;
On 7/30/11, brijesh brijeshupadhyay...@gmail.com wrote:
@ankur I didnt get this... could u or anyone please elaborate!
On Jul 30, 12:43 am, Ankur Khurana ankur.kkhur...@gmail.com wrote:
when you use itoa ,
hw will u get the ans on repeated subtraction from the sum of the digits??
I mean if I hv 2 divide 27 by 3 thn first I'll find sum of the digits
i.e, 2+7=9
then I'll apply repeated subtraction on 9, so hw will i reach to the ans??
On Sat, Jul 30, 2011 at 10:05 AM, nivedita arora
18 matches
Mail list logo