interview question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jerico
    New Member
    • Sep 2006
    • 39

    interview question

    Hi..I recently faced this question in an interview.How to multiply a number by 7 without using multiplication operator?I could not answer it.Thanks for any reply.

    jerico
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by jerico
    Hi..I recently faced this question in an interview.How to multiply a number by 7 without using multiplication operator?I could not answer it.Thanks for any reply.

    jerico
    you could add the number 7 times, e.g. k=j*7
    Code:
        k=0;
        for(int l=0; l<7; l++) k=k+j;
    you could shift left 3 bits (multiply by 8) and subtract, e.g.
    Code:
        j=(j<<3)-j;

    Comment

    • jerico
      New Member
      • Sep 2006
      • 39

      #3
      Thanks.

      jerico

      Comment

      Working...