how to use itoa() function to divide a number by 3 ?
Without using /,% and * operators. write a function to divide a number by 3, itoa() function is available.
mayank.dyl
Junior Poster in Training
71 posts since Sep 2009
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
Actually this is not my assignment problem. This problem was a part of a written exam.
Since i have never used itoa() function so i am little confused about its usage in dividing a number.
What i have come to know so far is this that itoa() function is used to convert integer to string and it also takes base value which is used to convert the input integer into a desired base for example base 10 to 8, 16 etc.
But the real problem is this that how it relates to dividing a number by 3.
please suggest !
mayank.dyl
Junior Poster in Training
71 posts since Sep 2009
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
okay, after considering your idea of just using subtraction and for loop, i have written following function but it no where makes use of itoa() function and further it assumes that we are not interested in remainder/decimals.
int divide(int a, int b) // dividing a by b and returing quotient
{
int A=a;
int B=b;
int n=0, i=0, j;
for (j=0; j<100; j++)
{
i=A-B;
A=i;
if(i<B)
{
n=n+1;
return n;
break;
}
else
n=n+1;
}
}
mayank.dyl
Junior Poster in Training
71 posts since Sep 2009
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0