Re: [algogeeks] Re: adobe written round que

2012-01-18 Thread Arun Vishwanathan
@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 Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
 People often say that motivation doesn't last. Well, neither does bathing
- that's why we recommend it daily.

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-09-21 Thread annarao kataru
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-09-17 Thread priyanka raju
*

*
*#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;
coutEnter the number : ;
cini;
check(i);
if(flag == true)
couti is divisible by '3'endl;
else
couti is not divisible by '3'endl;
}*

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-08-01 Thread Puneet Gautam
@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 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 not divisibility test ..but to get
 quotient :-|

 On Jul 30, 10:03 pm, Ankur Khurana ankur.kkhur...@gmail.com wrote:
  @roopam : i got the question all wrong. . .
 
  On Sat, Jul 30, 2011 at 10:01 PM, Roopam Poddar mailroo...@gmail.com
 wrote:
 
 
 
 
 
 
 
 
 
   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.
   So whats the point?
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To view this discussion on the web visit
  https://groups.google.com/d/msg/algogeeks/-/BWTzYtcBhIgJ.
 
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
  --
  Ankur Khurana
  Computer Science
  Netaji Subhas Institute Of Technology
  Delhi.

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 The more you sweat in the field, the less you bleed in war.

 Ankit Minglani
 NITK Surathkal

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-08-01 Thread shubham
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) = 1/4]

now s1-s2 upon simplifying becomes (x/3)

Implementation:

x1=x1;
x2=x2;
s1=x1;
s2=x2;
while(x1 || x2){
  s1+=x12;
  s2+=x22;
  x1=2;
  x2=2;
}
return s1-s2;

If the number is not divisible by 3 the answer returned is the least integer 
function of (x/3)
correct me if i am wrong...

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/YZjVTMk5JvEJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-07-31 Thread Ankit Minglani
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 not divisibility test ..but to get
 quotient :-|

 On Jul 30, 10:03 pm, Ankur Khurana ankur.kkhur...@gmail.com wrote:
  @roopam : i got the question all wrong. . .
 
  On Sat, Jul 30, 2011 at 10:01 PM, Roopam Poddar mailroo...@gmail.com
 wrote:
 
 
 
 
 
 
 
 
 
   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.
   So whats the point?
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To view this discussion on the web visit
  https://groups.google.com/d/msg/algogeeks/-/BWTzYtcBhIgJ.
 
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
  --
  Ankur Khurana
  Computer Science
  Netaji Subhas Institute Of Technology
  Delhi.

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
The more you sweat in the field, the less you bleed in war.

Ankit Minglani
NITK Surathkal

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread SAMM
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 apply repeated subtraction on 9, so hw will i reach to the ans??


 On Sat, Jul 30, 2011 at 10:05 AM, nivedita arora 
 vivaciousnived...@gmail.com wrote:


 @brijesh-
 itoa basically converts integer to string ..we are using the fact tht
 a number is multiple of 3 if its sum is multiple of 3
 . we have int as string and we can traverse it ..for each character
 apply
  int sum+=*c-'0' (ankur missed the star :P)
 then on sum we use repeated subtraction...i hope its clear .

 we are using all this just coz we have to use itoa ..otherwise there
 are more methods (check my frst post )


 On Jul 30, 4:34 am, 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 , what you get is a string. get the sum of all the
 digits
   , using c-'0' and then use repeated subtraction . . .
 
   On Sat, Jul 30, 2011 at 1:01 AM, sukhmeet singh 
 sukhmeet2...@gmail.comwrote:
 
repeated subtraction !!
 
On Sat, Jul 30, 2011 at 12:52 AM, nivedita arora 
vivaciousnived...@gmail.com wrote:
 
Without using /,% and * operators. write a function to divide a
 number
by 3. itoa() function is available.
 
all i cn thnk of is to use shift operator and addition ,
  x/3=e^(logx-
log3) or repetitive subtraction
 
but none of them uses itoa() ..ne idea how its done?
thnks !
 
--
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
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
 
 --
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
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
 
   --
   Ankur Khurana
   Computer Science
   Netaji Subhas Institute Of Technology
   Delhi.

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Somnath Singh

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread aditi garg
@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 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 apply repeated subtraction on 9, so hw will i reach to the
 ans??
 
 
  On Sat, Jul 30, 2011 at 10:05 AM, nivedita arora 
  vivaciousnived...@gmail.com wrote:
 
 
  @brijesh-
  itoa basically converts integer to string ..we are using the fact tht
  a number is multiple of 3 if its sum is multiple of 3
  . we have int as string and we can traverse it ..for each character
  apply
   int sum+=*c-'0' (ankur missed the star :P)
  then on sum we use repeated subtraction...i hope its clear .
 
  we are using all this just coz we have to use itoa ..otherwise there
  are more methods (check my frst post )
 
 
  On Jul 30, 4:34 am, 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 , what you get is a string. get the sum of all the
  digits
, using c-'0' and then use repeated subtraction . . .
  
On Sat, Jul 30, 2011 at 1:01 AM, sukhmeet singh 
  sukhmeet2...@gmail.comwrote:
  
 repeated subtraction !!
  
 On Sat, Jul 30, 2011 at 12:52 AM, nivedita arora 
 vivaciousnived...@gmail.com wrote:
  
 Without using /,% and * operators. write a function to divide a
  number
 by 3. itoa() function is available.
  
 all i cn thnk of is to use shift operator and addition ,
   x/3=e^(logx-
 log3) or repetitive subtraction
  
 but none of them uses itoa() ..ne idea how its done?
 thnks !
  
 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
  
  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
  
--
Ankur Khurana
Computer Science
Netaji Subhas Institute Of Technology
Delhi.
 
  --
  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
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
 
  --
  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
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 


 --
 Somnath Singh

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Aditi Garg
Undergraduate Student
Electronics  Communication Divison
NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
Sector 3, Dwarka
New Delhi

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Ankit Minglani
#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;
char p[20];
clrscr();
scanf(%d,x);
itoa(x,p,3);

rem=(int)p[strlen(p)-1]-48;
printf(%dRemainder\n,rem);

for(i=strlen(p)-2,j=0;i=0;i--,j++)
{
printf(p[j] = %d,p[j]-48);
 //quo+=(p[j]-48)*pow(3,i);
quo+=multiply(p[j]-48,pow(3,i));
printf(\nquo=%d,quo);

}

printf(\nQuotient=%d,quo);

printf(\n%s,p);
getch();

}

taking base 3 will convert the number into the base 3 form ..
for example let x=100 the number to be divided by three.

so 100 in base 10 = 10201 in base 3 .
we get base 3 by consecutive divisions by 3 so the last number will always
be the remainder ie 1 .

rest   1 0 2 0 will be the quotient.
  |  |  |  |
index:3 2 1 0
so p[j]-48 will convert the char to integer and mutiply it wil 3 ^ power (
index )
the answer will be the quotient.


On Sat, Jul 30, 2011 at 12:15 AM, aditi garg aditi.garg.6...@gmail.comwrote:

 @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 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 apply repeated subtraction on 9, so hw will i reach to the
 ans??
 
 
  On Sat, Jul 30, 2011 at 10:05 AM, nivedita arora 
  vivaciousnived...@gmail.com wrote:
 
 
  @brijesh-
  itoa basically converts integer to string ..we are using the fact tht
  a number is multiple of 3 if its sum is multiple of 3
  . we have int as string and we can traverse it ..for each character
  apply
   int sum+=*c-'0' (ankur missed the star :P)
  then on sum we use repeated subtraction...i hope its clear .
 
  we are using all this just coz we have to use itoa ..otherwise there
  are more methods (check my frst post )
 
 
  On Jul 30, 4:34 am, 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 , what you get is a string. get the sum of all
 the
  digits
, using c-'0' and then use repeated subtraction . . .
  
On Sat, Jul 30, 2011 at 1:01 AM, sukhmeet singh 
  sukhmeet2...@gmail.comwrote:
  
 repeated subtraction !!
  
 On Sat, Jul 30, 2011 at 12:52 AM, nivedita arora 
 vivaciousnived...@gmail.com wrote:
  
 Without using /,% and * operators. write a function to divide a
  number
 by 3. itoa() function is available.
  
 all i cn thnk of is to use shift operator and addition ,
   x/3=e^(logx-
 log3) or repetitive subtraction
  
 but none of them uses itoa() ..ne idea how its done?
 thnks !
  
 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
  
  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
  
--
Ankur Khurana
Computer Science
Netaji Subhas Institute Of Technology
Delhi.
 
  --
  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
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
 
  --
  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
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 


 --
 Somnath Singh

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post 

Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Puneet Gautam
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..!!

Hence, itoa becomes useful..!

Thanks..

On 7/30/11, Ankit Minglani ankit.mingl...@gmail.com wrote:
 #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;
 char p[20];
 clrscr();
 scanf(%d,x);
 itoa(x,p,3);

 rem=(int)p[strlen(p)-1]-48;
 printf(%dRemainder\n,rem);

 for(i=strlen(p)-2,j=0;i=0;i--,j++)
 {
 printf(p[j] = %d,p[j]-48);
  //quo+=(p[j]-48)*pow(3,i);
 quo+=multiply(p[j]-48,pow(3,i));
 printf(\nquo=%d,quo);

 }

 printf(\nQuotient=%d,quo);

 printf(\n%s,p);
 getch();

 }

 taking base 3 will convert the number into the base 3 form ..
 for example let x=100 the number to be divided by three.

 so 100 in base 10 = 10201 in base 3 .
 we get base 3 by consecutive divisions by 3 so the last number will always
 be the remainder ie 1 .

 rest   1 0 2 0 will be the quotient.
   |  |  |  |
 index:3 2 1 0
 so p[j]-48 will convert the char to integer and mutiply it wil 3 ^ power (
 index )
 the answer will be the quotient.


 On Sat, Jul 30, 2011 at 12:15 AM, aditi garg
 aditi.garg.6...@gmail.comwrote:

 @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 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 apply repeated subtraction on 9, so hw will i reach to the
 ans??
 
 
  On Sat, Jul 30, 2011 at 10:05 AM, nivedita arora 
  vivaciousnived...@gmail.com wrote:
 
 
  @brijesh-
  itoa basically converts integer to string ..we are using the fact tht
  a number is multiple of 3 if its sum is multiple of 3
  . we have int as string and we can traverse it ..for each character
  apply
   int sum+=*c-'0' (ankur missed the star :P)
  then on sum we use repeated subtraction...i hope its clear .
 
  we are using all this just coz we have to use itoa ..otherwise there
  are more methods (check my frst post )
 
 
  On Jul 30, 4:34 am, 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 , what you get is a string. get the sum of all
 the
  digits
, using c-'0' and then use repeated subtraction . . .
  
On Sat, Jul 30, 2011 at 1:01 AM, sukhmeet singh 
  sukhmeet2...@gmail.comwrote:
  
 repeated subtraction !!
  
 On Sat, Jul 30, 2011 at 12:52 AM, nivedita arora 
 vivaciousnived...@gmail.com wrote:
  
 Without using /,% and * operators. write a function to divide a
  number
 by 3. itoa() function is available.
  
 all i cn thnk of is to use shift operator and addition ,
   x/3=e^(logx-
 log3) or repetitive subtraction
  
 but none of them uses itoa() ..ne idea how its done?
 thnks !
  
 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
  
  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
  
--
Ankur Khurana
Computer Science
Netaji Subhas Institute Of Technology
Delhi.
 
  --
  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
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
 
  --
  You received this message because you 

Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Abhishek Gupta
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
 #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;
 char p[20];
 clrscr();
 scanf(%d,x);
 itoa(x,p,3);

 rem=(int)p[strlen(p)-1]-48;
 printf(%dRemainder\n,rem);

 for(i=strlen(p)-2,j=0;i=0;i--,j++)
 {
 printf(p[j] = %d,p[j]-48);
  //quo+=(p[j]-48)*pow(3,i);
 quo+=multiply(p[j]-48,pow(3,i));
 printf(\nquo=%d,quo);

 }

 printf(\nQuotient=%d,quo);

 printf(\n%s,p);
 getch();

 }

 taking base 3 will convert the number into the base 3 form ..
 for example let x=100 the number to be divided by three.

 so 100 in base 10 = 10201 in base 3 .
 we get base 3 by consecutive divisions by 3 so the last number will always
 be the remainder ie 1 .

 rest   1 0 2 0 will be the quotient.
   |  |  |  |
 index:3 2 1 0
 so p[j]-48 will convert the char to integer and mutiply it wil 3 ^ power (
 index )
 the answer will be the quotient.



 On Sat, Jul 30, 2011 at 12:15 AM, aditi garg aditi.garg.6...@gmail.comwrote:

 @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 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 apply repeated subtraction on 9, so hw will i reach to the
 ans??
 
 
  On Sat, Jul 30, 2011 at 10:05 AM, nivedita arora 
  vivaciousnived...@gmail.com wrote:
 
 
  @brijesh-
  itoa basically converts integer to string ..we are using the fact tht
  a number is multiple of 3 if its sum is multiple of 3
  . we have int as string and we can traverse it ..for each character
  apply
   int sum+=*c-'0' (ankur missed the star :P)
  then on sum we use repeated subtraction...i hope its clear .
 
  we are using all this just coz we have to use itoa ..otherwise there
  are more methods (check my frst post )
 
 
  On Jul 30, 4:34 am, 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 , what you get is a string. get the sum of all
 the
  digits
, using c-'0' and then use repeated subtraction . . .
  
On Sat, Jul 30, 2011 at 1:01 AM, sukhmeet singh 
  sukhmeet2...@gmail.comwrote:
  
 repeated subtraction !!
  
 On Sat, Jul 30, 2011 at 12:52 AM, nivedita arora 
 vivaciousnived...@gmail.com wrote:
  
 Without using /,% and * operators. write a function to divide a
  number
 by 3. itoa() function is available.
  
 all i cn thnk of is to use shift operator and addition ,
   x/3=e^(logx-
 log3) or repetitive subtraction
  
 but none of them uses itoa() ..ne idea how its done?
 thnks !
  
 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
  
  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
  
--
Ankur Khurana
Computer Science
Netaji Subhas Institute Of Technology
Delhi.
 
  --
  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
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
 
  --
  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 

Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Roopam Poddar
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.
So whats the point?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/BWTzYtcBhIgJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Ankur Khurana
@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 divisibility by 3 and not give us the quotient.
 To get that you will have to carry out repeated subtraction on the number
 anyway.
 So whats the point?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/BWTzYtcBhIgJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Ankur Khurana
Computer Science
Netaji Subhas Institute Of Technology
Delhi.

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Puneet Gautam
@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 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 divisibility by 3 and not give us the quotient.
 To get that you will have to carry out repeated subtraction on the number
 anyway.
 So whats the point?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/BWTzYtcBhIgJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Ankur Khurana
 Computer Science
 Netaji Subhas Institute Of Technology
 Delhi.

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-07-29 Thread aditi garg
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 vivaciousnived...@gmail.com
 wrote:
  hmm ok got it . ..i can take gt sum of digits without having the
  number as string as well . i din exactly gt the whole point of using
  strings.
  they shud hv mentioned it explicitly i guess . .
  though thanks ankur
 
  On Jul 30, 1:15 am, Ankur Khurana ankur.kkhur...@gmail.com wrote:
 
 
 
 
 
 
 
   you shouldn't be using itoa anyways. It is not a part of ANSI C. you
 might
   like to use sprintf . you can search for reference on cplusplus.com
 
   On Sat, Jul 30, 2011 at 1:36 AM, aditi garg aditi.garg.6...@gmail.com
 wrote:
 
@Ankur: I dont know how to use itoa function...can u please write a
 small
code...for eg in dis ques only can u tell me how to use itoa to get
 sum...
 
On Sat, Jul 30, 2011 at 1:13 AM, Ankur Khurana 
 ankur.kkhur...@gmail.comwrote:
 
when you use itoa , what you get is a string. get the sum of all the
digits , using c-'0' and then use repeated subtraction . . .
 
On Sat, Jul 30, 2011 at 1:01 AM, sukhmeet singh 
 sukhmeet2...@gmail.comwrote:
 
repeated subtraction !!
 
On Sat, Jul 30, 2011 at 12:52 AM, nivedita arora 
vivaciousnived...@gmail.com wrote:
 
Without using /,% and * operators. write a function to divide a
 number
by 3. itoa() function is available.
 
all i cn thnk of is to use shift operator and addition ,
  x/3=e^(logx-
log3) or repetitive subtraction
 
but none of them uses itoa() ..ne idea how its done?
thnks !
 
--
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
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
 
 --
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
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
 
--
Ankur Khurana
Computer Science
Netaji Subhas Institute Of Technology
Delhi.
 
 --
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
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
 
--
Aditi Garg
Undergraduate Student
Electronics  Communication Divison
NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
Sector 3, Dwarka
New Delhi
 
 --
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
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
 
   --
   Ankur Khurana
   Computer Science
   Netaji Subhas Institute Of Technology
   Delhi.

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Aditi Garg
Undergraduate Student
Electronics  Communication Divison
NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
Sector 3, Dwarka
New Delhi

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-07-29 Thread Sudhir mishra
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 Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-07-29 Thread ananth sharma
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 , what you get is a string. get the sum of all the
 digits
 , using c-'0' and then use repeated subtraction . . .

 On Sat, Jul 30, 2011 at 1:01 AM, sukhmeet singh
 sukhmeet2...@gmail.comwrote:









  repeated subtraction !!

  On Sat, Jul 30, 2011 at 12:52 AM, nivedita arora 
  vivaciousnived...@gmail.com wrote:

  Without using /,% and * operators. write a function to divide a number
  by 3. itoa() function is available.

  all i cn thnk of is to use shift operator and addition ,  x/3=e^(logx-
  log3) or repetitive subtraction

  but none of them uses itoa() ..ne idea how its done?
  thnks !

  --
  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
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

   --
  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
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

 --
 Ankur Khurana
 Computer Science
 Netaji Subhas Institute Of Technology
 Delhi.

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
ThanksRegards,
Anantha Krishna Sharma.Kalle
eMail-Id:ananthakrishna.ka...@gmail.com
Ph. No:+91-9036116130

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: adobe written round que

2011-07-29 Thread tech rascal
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 
vivaciousnived...@gmail.com wrote:


 @brijesh-
 itoa basically converts integer to string ..we are using the fact tht
 a number is multiple of 3 if its sum is multiple of 3
 . we have int as string and we can traverse it ..for each character
 apply
  int sum+=*c-'0' (ankur missed the star :P)
 then on sum we use repeated subtraction...i hope its clear .

 we are using all this just coz we have to use itoa ..otherwise there
 are more methods (check my frst post )


 On Jul 30, 4:34 am, 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 , what you get is a string. get the sum of all the
 digits
   , using c-'0' and then use repeated subtraction . . .
 
   On Sat, Jul 30, 2011 at 1:01 AM, sukhmeet singh 
 sukhmeet2...@gmail.comwrote:
 
repeated subtraction !!
 
On Sat, Jul 30, 2011 at 12:52 AM, nivedita arora 
vivaciousnived...@gmail.com wrote:
 
Without using /,% and * operators. write a function to divide a
 number
by 3. itoa() function is available.
 
all i cn thnk of is to use shift operator and addition ,
  x/3=e^(logx-
log3) or repetitive subtraction
 
but none of them uses itoa() ..ne idea how its done?
thnks !
 
--
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
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
 
 --
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
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.
 
   --
   Ankur Khurana
   Computer Science
   Netaji Subhas Institute Of Technology
   Delhi.

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.