We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,560 Members — Technology Publication meets Social Media

# 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.

2
Contributors
3
Replies
12 Hours
Discussion Span
1 Year Ago
Last Updated
5
Views
mayank.dyl
Junior Poster in Training
71 posts since Sep 2009
Reputation Points: 10
Skill Endorsements: 0

If you think about it you can divide by just using subtraction and a for() loop. Since you have this function itoa() available I'm assuming you are only using integers, which means you do not have to worry about remainders/decimals.

Not gonna give you any code because you clearly just rewrote the assignment requirements, so give it a shot and if you have any questions post code and outline where you are having issues.

sfuo
Master Poster
713 posts since Jul 2009
Reputation Points: 173
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.

mayank.dyl
Junior Poster in Training
71 posts since Sep 2009
Reputation Points: 10
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