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

Recommended Answers

All 3 Replies

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.

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 !

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;

  }
}   
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.