rewrite the code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harimca14
    New Member
    • Sep 2007
    • 3

    rewrite the code

    Rewrite the following function so that the following conditions are satisfied:
    a. The multiplication operator ('*') is not used.
    b. The division operator ('/') is not used.
    c. The function does not make use of loops.
    d. DO NOT use assembly
    int MultiplyBy321(i nt value) {
    int rslt;
    rslt = value * 321;
    return rslt;
    }
  • mattmao
    New Member
    • Aug 2007
    • 121

    #2
    Originally posted by harimca14
    Rewrite the following function so that the following conditions are satisfied:
    a. The multiplication operator ('*') is not used.
    b. The division operator ('/') is not used.
    c. The function does not make use of loops.
    d. DO NOT use assembly
    int MultiplyBy321(i nt value) {
    int rslt;
    rslt = value * 321;
    return rslt;
    }
    ??? where is the division operator ('/') in your sample code???

    OR your meaning is to use four different approaches to do the same operation as the sample?

    I am not knowing if this question comes from a textbook, anyway, I give you my stupid answer to the first one:
    a. The multiplication operator ('*') is not used.

    int MultiplyBy321(i nt value)
    {
    <spoonfeeding code removed>
    weaknessforcats
    }

    BTW, if what you want is to satisfy all the a-d requirements, then you should wait for some real experts to answer this tricky question...

    Comment

    • Studlyami
      Recognized Expert Contributor
      • Sep 2007
      • 464

      #3
      Take a look at this article its about how bit shifting can simulate multiplication
      http://www.cprogrammin g.com/tips/showTip.php?tip =66&count=30&pa ge=0

      Comment

      • shruthibhat
        New Member
        • Sep 2007
        • 2

        #4
        Originally posted by harimca14
        Rewrite the following function so that the following conditions are satisfied:
        a. The multiplication operator ('*') is not used.
        b. The division operator ('/') is not used.
        c. The function does not make use of loops.
        d. DO NOT use assembly
        int MultiplyBy321(i nt value) {
        int rslt;
        rslt = value * 321;
        return rslt;
        }
        instead of the "rslt=value*321 " one can code as
        rslt=value+valu e+value........ ....so on for 321 times.......... ...... :D .

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

          Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

          Then when you are ready post a new question in this thread.

          MODERATOR

          Comment

          Working...