Dividing two numbers

You are given two numbers A and B,
You have to divide A by B without using division operator and modulus operator ?

PS: Repeated Subtraction is not allowed..

I have thought of a solution but i am not satisfied with that so asking for help of CEans

Replies

  • srinivas_j
    srinivas_j
    hi!! dude the following code serves your purpose!!
    #include
    void main()
    {
    float a,b,r=0;
    printf("\n\n\tEnter Values of a & b :");
    scanf("%d%d",&a,&b);
    while(b*r <= a)
    r++;
    printf("\n\n\tAnswer is : %d ",r-1);
    }

    Have a Nice time!!(Note : It's for Integers!! ie, i've not taken floating point division to easy the task!!)
  • Sachin Jain
    Sachin Jain
    Thats OK...Actually its a YAHOO interview question.
    I thought of doing like this :-
    We have to calculate y=A/B
    So take log of both sides
    log y=log(A/B)
    log y=log A - log B
    calculate log A - log B=x say
    Then take antilog both sides
    y=antilog (x)

    In this way we can find A/b without using / and % operator.
    Thats what i thought
  • silverscorpion
    silverscorpion
    srinivas_j
    hi!! dude the following code serves your purpose!!
    #include
    void main()
    {
    float a,b,r=0;
    printf("\n\n\tEnter Values of a & b :");
    scanf("%d%d",&a,&b);
    while(b*r <= a)
    r++;
    printf("\n\n\tAnswer is : %d ",r-1);
    }

    Have a Nice time!!(Note : It's for Integers!! ie, i've not taken floating point division to easy the task!!)
    Here, I think the printf statement should be outside the while loop!! 😀
  • srinivas_j
    srinivas_j
    no!! it's not inside d while loop!! it's outside itself try it out by Executing!!
  • prabait28
    prabait28
    Tell me Any other crct answer with simple concept.....
  • srinivas_j
    srinivas_j
    it's d simplest one & it takes very less cpu cycle time compared to ur other method!! & mor over logic is simple!

You are reading an archived discussion.

Related Posts

Md5

In cryptography, MD5 (Message-Digest algorithm 5) is a widely used cryptographic hash function with a 128-bit hash value. Specified in RFC 1321, MD5 has been employed in a wide variety...
This should be my first thread in this forum(CE).:smile: I'm trying to build a gsm activated car security. Will someone tell me where to tap the signal that will activate...
Note: The below points about QTP 11.0 is copied from a presentation I have prepared gathering data from various sources. New Features in QTP •[FONT="] [/FONT]XPath and CSS based object...
What are all the practical applications of MATLAB software, other than simulating electrical, electronic, and computer languages? any example practically? And why it is considered the most important tool for...
today i wrote some code and complied it, till it was good. when i executed the code, server got crashed. error was illegeal bytecode. i want to know ,by how...